Casting – foreach – java-Collection of common programming errors
I have a one method like this:
private void myMethod(List myLists) {
for (Object val : myLists) {
val.getMyOtherMethod(); // for example
}
}
How can I casting val to one of my objects?
All my objects (list objects) contain same methods, like as getMyOtherMethod()
BR
edit: ———————————————————————
I called myMethod few times, like as:
List var1;
List var1;
List var1;
...
...
myMethod(var1);
myMethod(var2);
myMethod(var3);
In this case, I do not know, witch subclass I send MySubclass1, MySubclass2 or MySubclass3. That is important for foreach loop.