odd behavior with java collections of parameterized Class objects
- by Paul
Ran into some questionable behavior using lists of parameterized Class objects:
ArrayList<Class<String>> classList = new ArrayList<Class<String>>();
classList.add(Integer.class); //compile error
Class intClass = Integer.class;
classList.add(intClass); //legal apparently, as long as intClass is not parameterized
Found the same behavior for LinkedList, haven't tried other collections. Is it like this for a reason? Or have I stumbled on something?