Say you have custom generic class MyList<Elm extends ListElm>
where ListElm is an interface. Now you have client code working with a concrete instance of MyList, instantiated using an implementor of ListElm, which also happens to have some of its own methods which are not part of the ListElm interface:
MyList<ListElmClass> myList = new MyList<ListElmClass>();
myList.someMethodFromListElmClass(); // where someMethodFromListElmClass() exists in ListElmClass but not in ListElm
The code above won't work as is. I am required to manually cast "myList" to "ListElmClass" before calling someMethodFromListElmClass
1. Is it bad form to do this? If so, what is the better way?
2. Why doesn't this work? Is it something to do with erasure?