Typed DefaultListModel to avoid casting

Posted by Thomas R. on Stack Overflow See other posts from Stack Overflow or by Thomas R.
Published on 2010-03-30T22:30:58Z Indexed on 2010/03/30 22:33 UTC
Read the original article Hit count: 258

Filed under:
|
|
|
|

Is there a way in java to have a ListModel that only accepts a certain type? What I'm looking for is something like DefaultListModel<String> oder TypedListModel<String>, because the DefaultListModel only implements addElement(Object obj) and get(int index) which returns Object of course.

That way I always have to cast from Object to e.g. String and there is no guarantee that there are only strings in my model, even though I'd like to enforce that.

Is this a flaw or am I using list models the wrong way?

© Stack Overflow or respective owner

Related posts about java

Related posts about list