Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

object of an interface? Hows possible

 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



The above code is compilable. I wonder how can we make object of Interface Runnable.
What is this concept? :evil:
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search for the term "anonymous class".
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually this is not an object of an interface however in a piece of code like this one you are extending/implementing the specified class/interface and then you override the needed methods. this method is named anonymos classes. and if you ever written swing code all your listeners are generally created in this way.

 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Search for the term "anonymous class".


DOH! Thanks Rob, I have been wondering about this myself for a while, makes perfect sense now!
ops:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic