java - Lack of optional methods/operations of an implemented interface causing errors -
** Not sure if this is clear, but I am writing Java
I I'm trying to complete an assignment for a class, for which I want to ListIterator & lt; String & gt; I need to implement the interface I do not want to implement the
deletion ()
, add ()
, or set ()
, Which are alternative methods for the interface. But now it has been implemented, Eclipse is telling me the errors that I need to implement those methods. Does anyone know why this is or how can I solve it? Thank you in advance for your assistance.
They are not really optional.
You have to provide some sort of implementation, but it is common to provide an implementation which throws an exception:
Generating a zero () { New unsupported operation exception (); }
In some situations it may also be appropriate to provide a "Nothing" implementation:
Remove public zeros () {/ / Can not remove ...}
If you do any of these, it is a good idea to document that you have done it.
If you have an abstract class, then you do not need to apply the methods in this specific class. But at some points of class hierarchy, you have to implement a solid square with all the methods. Nothing really happens until you instantiate your class in an example, and you can not do it with an abstract class.
Comments
Post a Comment