Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why there was need for AutoCloseable when Closeable was already there?  RSS feed

 
gurpreet singh mahngar
Greenhorn
Posts: 1
Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

K& B 7 chapter on Exceptions says that  Language designers added AutoCloseable because Closeable Interface throw only IOException and they wanted to have something more generic. If this was their motive , they might have as well modified the Closeable Interface and changed IOException to Exception.
Would it caused any problem in terms of backword compatibility ? I think it should not because Closeable interface has close with IOException, so any class using Closeable will have IOException or subclass and even if they chagne Closeable's close to Exception, the code will still compile and run. Am i missing
something here ?
 
Tobias Bachert
Ranch Hand
Posts: 60
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would have broken backward compatibility. If Closeable#close would have been changed to throw Exception, then every caller that calls #close on a Closeable reference and only catches IOException would no longer compile.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!