I was just wondering why java.util.Scanner is implementing java.util.Iterator.
Scanner
is implementing the remove method and throws an UnsupportedOperationException.
But shouldn't a class, when implementing an interface, suppose to fulfill the contract of the interface?
What is the use of implementing iterator
and adding a method that throws an exception?
Why not just avoid the implementation of the interface and keep it simple?
One can argue that it is defined so that the class which might extend Scanner
could implement the method, like AbstractList has an add method that throws an UnsupportedOperationException
. But theAbstractList
is an abstract
class, where as Scanner
is a final
class.
Is it not a bad design practice..?
Aucun commentaire:
Enregistrer un commentaire