If I use unlimited lookup types for two collections (each collection will have a different type ) as arguments to the method:
private void doAssertion(List<?> testList, List<?> generatedList)
Inside this method, can I first check the type of objects in these collections, and then pass the collection to a parameterized type? It just smells bad and I get a warning without warning.
if (testList.get(0) instanceof X) { List<X> xList = (List<X>) testList; // call methods specific to X for each object } else if (testList.get(0) instanceof Y){ List<Y> yList = (List<Y>) testList; // call methods specific to Y for each object }
Part of my problem is that I have no way to touch the code that defines the classes X or Y. Otherwise, I know that I can implement them for a common interface and use a parameter of a limited type. I cannot overload assertEqual because both methods have the same erase.
In my case, X and Y will always be child classes of other classes, and I donβt modify objects at all by simply calling the get() methods of the objects.
source share