To prevent memory leaks with JNI GlobalRefs, there are restrictions for using method return values. To call a method on a return value, the return value must be explicitly converted to the expected type. In the following example, the first line is valid because it converts the return value from mc.myStringMethod to a String before calling length(). The second line is not valid:
jint len = String(mc.myStringMethod()).length(); jint len = mc.myStringMethod().length(); // invalid