Typed DefaultListModel to avoid casting
- by Thomas R.
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?