While coding I created a class that extends ArrayList<>
and implements Iterable<>
. The code is :
public class Testclass extends ArrayList<Object>, implements Iterable<Object> { }
Netbeans reported an error:
'{' expected
How to prevents this?
From the comments:
error is '{' expected
code is this
public class Testclass extends ArrayList<Object>, implements Iterable<Object> { }
Remove that comma ,
. It doesn't belong there. It's just a syntax error.
In the future, please read the error message. If you can't interpret it, even not after a little Googling, just ask it here, complete with the entire error message and the code which caused it. This way you will get better suited answers sooner than guessing randomly for the cause ;)
ArrayList does not implement Iterator. Maybe you mean Iterable?
Anyway, it is not a problem to implement an interface that a superclass already implements (it is just redundant).
What error are you getting? It seems to be about something else. If you are using generics, did you make sure the types match on superclass and interface?
Also, it seems to be against the spirit of the Collection and Iterator interfaces to have an object that is both at the same time. At the very least, it is quite confusing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With