Rachit Pant wrote:I am writing iterator method of a class.
The structure of class is as:
class A{
TypeX[] typex;
public Iterator<TypeX> iterator() {} // this is the method i wanna write
}
I tried this in my iterator methods code:
return Arrays.asList(typex).iterator();
This will return the Iterator<TypeX> as required , but i want my iterator to throw an UnsupportedOperationException, when i call its remove method.
So I need to override this method.
Can someone tell me how to do this??
There is no black magic here... The easiest way to override a method, is to actually override the method. This means that you need access to the super class to inherit from. And since you don't, you can either (1) write a wrapper iterator or better yet (2) write an iterator (there is only three methods) that iterates your data structure.
Henry