This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Runnable to Thread Casting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Runnable to Thread Casting" Watch "Runnable to Thread Casting" New topic
Author

Runnable to Thread Casting

Balaji Bang
Ranch Hand

Joined: Apr 23, 2007
Posts: 182



Why the casting gives ClassCastException? Thread class provides the implementation for Runnable interface. Then why cannot we cast???
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
This is because r1 is an implementer of the Runnable Interface. Thread class also is an implementer of Runnable. But there is no relation between r1(anonymous sub-class referenced by r1) and the Thread class.
Balaji Bang
Ranch Hand

Joined: Apr 23, 2007
Posts: 182

ohhhhhh. Yes r1 is just an implementor reference not Runnable reference. So we cannot . Thank you
 
 
subject: Runnable to Thread Casting
 
It's not a secret anymore!