|
|
|
|||||||||||||||||||||||||||||||||
|
Mapping between Java and Native TypesIn this section, you will learn how to reference Java types in your native method. You need to do this when you want to:
Java Primitive Types Your native method can directly access Java primitive
types such as booleans, integers, floats, and so on, that are passed
from programs written in Java. For example, the Java type
Java Object Types
Java objects are passed by reference. All references to Java objects have the
type ![]() This figure has been reduced to fit on the page. Click the image to view it at its natural size. In our Its corresponding native implementation has typeprivate native String getLine(String prompt); jstring for both the argument and the return value:
JNIEXPORT jstring JNICALL Java_Prompt_getLine(JNIEnv *, jobject, jstring); Graphically, this looks as follows: ![]() This figure has been reduced to fit on the page. Click the image to view it at its natural size. jstring corresponds to the Java type
String. Notice that the second argument to Java_Prompt_getLine, which is the reference to the object
itself, has type jobject.
| |||||||||||||||||||||||||||||||||
|