aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Declaring a native as final Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Declaring a native as final" Watch "Declaring a native as final" New topic
Author

Declaring a native as final

Tejas Tambe
Ranch Hand

Joined: Oct 08, 2001
Posts: 47
A final method must have a method body, other wise it gives complation error.
On the other hand a native method should not have method body like abstract methods.
But,

is however considered to be a valid statement.
Can anyone explain the reason behind this.
Thanx in advance,
Tejas Tambe
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
A native method declaration is just like an interface method declaration; the actual body of the method is implemented someplace else. In the case of the native method, the "some place else" is a native library. If the compiler can't actually locate the native implementation in the library, you get a compiler error, but if you do find it, it creates the links to that code just fine, and when you call your java method, it dispatches that call to the native API.
It can be final so that the method is not overriden by some other method.
Now what I dont know and will have to research is , what happens if the native method is NOT final and another class overrides it? Can that class then implement some all-java version and not even use the native library routine? Interesting question!

Rob


Rob
SCJP 1.4
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
Originally posted by Rob Ross:
A native method declaration is just like an interface method declaration; the actual body of the method is implemented someplace else. In the case of the native method, the "some place else" is a native library. If the compiler can't actually locate the native implementation in the library, you get a compiler error, but if you do find it, it creates the links to that code just fine, and when you call your java method, it dispatches that call to the native API.
It can be final so that the method is not overriden by some other method.
Now what I dont know and will have to research is , what happens if the native method is NOT final and another class overrides it? Can that class then implement some all-java version and not even use the native library routine? Interesting question!

Rob


I believe you can override a native method to be non-native...
Ragu
[ January 13, 2002: Message edited by: Ragu Sivaraman ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Declaring a native as final