This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reg. runnable - interface??!

 
Ravi Chilakapati
Greenhorn
Posts: 10
  • 0
  • 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: 4549
8
Java Netbeans IDE Scala
  • 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
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic