Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Declaring a native as final

 
Tejas Tambe
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ragu Sivaraman
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic