Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AbstractMethodError

 
Sudarshan Sreenivasan
Ranch Hand
Posts: 188
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Can you tell me when a AbstractMethodError occurs ?? The api says

Thrown when an application tries to call an abstract method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled.


I need an example situation of when this can happen at runtime ?? , I can not think of a situation where this could happen, can anyone throw light on it

Thanks
Sudarshan
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create an empty interface

interface I {}

Create a class that implements it:

class C implements I {}

Now compile them both.

Now modify the interface:

interface I { void m(); }

Compile interface I, if you like, but do not compile class C.

Now create a class which uses the interface.



Compile only class A and run it, and you'll get an AbstractMethodError. Class C has not been compiled since interface I changed, so it does not include an implementation of method m().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic