File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing Interface methods in implementing class....

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The throws clauses about Exceptions in the interface's methods must exactly match the throws clauses of the implementing methods. That means, we can't even declare the implemented methods as subclass of that Exception. Please confirm, I got it from a Note. Thanks in Advanced!~
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In K&B's book, It's said that, A nonabstract implementing class must not declare any new checked exceptions for an implementation method. That means, We can't declare a subclass type Exception in the method declaration. Please confirm!
 
Neha Daga
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its not like that,
always remember overriding methods cannot declare newer or broader checked exceptions.
example:


here version 1,2 and 5 are allowed but version 3 and 4 are not allowed.
 
Jeevan Reddy
Ranch Hand
Posts: 142
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Neha for the clarification.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An implementation cannot throw new checked exceptions or broader checked exceptions. An implementation can as Neha demonstrated with her example throw a smaller exception (FileNotFoundException vs IOException). Of course can an implementation throw new RuntimeExceptions (lowercase T).
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nega Daga & Wouter Oet. It's clear now. Thanks a lot......
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic