odd behavior with java collections of parameterized Class objects
        Posted  
        
            by 
                Paul
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Paul
        
        
        
        Published on 2011-01-07T23:46:27Z
        Indexed on 
            2011/01/07
            23:54 UTC
        
        
        Read the original article
        Hit count: 231
        
java
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?
© Stack Overflow or respective owner