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

Reg. runnable - interface??!

 
Ravi Chilakapati
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
The code below is getting compiled.



I thought that Runnable was an interface? I read about Runnable at several places on the net, and yet, I fail to understand why this statement is valid.



I have observed that other interfaces can also be created like this.
Can someone please elaborate on this?

Regards,
Ravi.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what's called an "anonymous inner class" (search for that and you'll find lots of references). You aren't creating an instance of Runnable (which is what you'd be doing without the {...} part). Instead you're creating an anonymous inner class that implements Runnable and creating an instance of that.

Look in the folder where the .class files go once you've compiled it, and you'll see there's an extra class in there.
 
Ravi Chilakapati
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Brown
Hmm.. interesting.. it makes a lot more sense now. Thank you!
Regards,
Ravi.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic