I was working with my code and found that adding an element into Collection thrown UnsupportedOperationException.
Lets say Class A contains a list of object X as its member, so adding new object X to list of Object x like
A a;
a.getXList().add(new X()) throws UnsupportedOperationException.
Why is it so?
Lets say Class A contains a list of object X as its member, so adding new object X to list of Object x like
A a;
a.getXList().add(new X()) throws UnsupportedOperationException.
Why is it so?
Will be helpful if you could provide more details about the collection you use.
ReplyDeleteIt may be because the list does not support addition of objects or may be because the new object that is being tried to add fails to satisfy some precondition so the list stops it from being added by throwing exception.