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

native abstract method

 
Serge Plourde
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the book by Sierran and Bates, it is written (p.90) <b>Native Methods</b>... native can <i>never</i> be combined with abstract...

But, in the self test that follows the chapter, "private native void m1();" is shown as legal! I tested it, and it is true.

I know, the abstract keyword is not shown, but I thought that ending a method declaration with ";" after the "()" was indicating the compiler as abstract. If this is an abstract method declaration, why does the compiler not complain that it must be declared as abstract?
 
Ariel Ortiz
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know, the abstract keyword is not shown, but I thought that ending a method declaration with ";" after the "()" was indicating the compiler as abstract. If this is an abstract method declaration, why does the compiler not complain that it must be declared as abstract?


This is not so. When the method body is missing it means that it is defined else where. In the case of abstract methods, the subclasses are responsible for providing the implementation. In the case of native methods, the code is implemented in another language (usaually C/C++) and made available through a dynamic link library at runtime.

...Ariel
 
Serge Plourde
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

Finally, what is important to know here is
A method that is native is implemented in platform-dependent code
JLS 3rd edition, 8.4.3.4 native Methods.

Even though the code of the method declaration looks abstract a native method is implemented!
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Serge Plourde:
In the book by Sierran and Bates, it is written (p.90) <b>Native Methods</b>... native can <i>never</i> be combined with abstract...

But, in the self test that follows the chapter, "private native void m1();" is shown as legal! I tested it, and it is true.

I know, the abstract keyword is not shown, but I thought that ending a method declaration with ";" after the "()" was indicating the compiler as abstract. If this is an abstract method declaration, why does the compiler not complain that it must be declared as abstract?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic