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

Inheritance and Polymorphism Involving Interface Casting

 
Jae Lim
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers!
Can someone please explain me how compiler is always happy with interface casting? Please look at the code below.
Any help is appreciated..!

 
Himalay Majumdar
Ranch Hand
Posts: 324
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In line 15, _A does not implement interface, but a subclass of it might implement it. Hence it is allowed.

Only when the class is final..compiler is sure it cannot have subclasses..and hence they cannot implement the interface.

In the last line of your code ..Line 28



..if you try to cast c (which is final) instead of a..you can upset the compiler then
 
Jae Lim
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the explanation it makes sense now.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic