Thursday, July 12, 2018

java - A method with no statements inside and ends with a semicolon




So I came across a method like this in some source



public native void method();


There was code inside, but it was commented out,




/*MANUAL code code code */


The code looked a bit like C++.
So what does this mean? I know it does something because eventually it was called in the class...


Answer



That's a declaration for a native method, indicated by the native modifier, as explained in the Java Language Specification, section §8.4.3.4 native Methods .



You won't find its implementing code in Java, it's referring to code that's either in the C libraries that are part of the implementation of the JDK in use, or part of a native library bundled with the code you're studying. Refer to the JNI documentation to understand how this gets called from a Java program.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...