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

Polymorphism and exceptions

 
Joey Sanchez
Ranch Hand
Posts: 88
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class A method m() throw an Exception that have to be handled even if the method called is from class B.

Is that because the method invocation is done at runtime based on object reference but the compilations take care of reference type?

 
Karn Kumar
Ranch Hand
Posts: 153
Eclipse IDE Java Tomcat Server
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes , the compiler will check for the polymorphic reference and method defined in it .So here class A reference is polymorphic reference hence compiler will check the method in A and hence we need to handle it ...
 
Joey Sanchez
Ranch Hand
Posts: 88
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, it's a little tricky.
 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rule of thumb , Compiler can only verify type information and not the Object related information. here Compiler thinks method m() from A and not B.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic