Java Generics - What's really in a unbounded wildcard?

后端 未结 2 1547

If i have the following code :

public static void main(String [] args) {  
        List  l2 = new ArrayList ();  
        List &l         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-23 06:27

    The unbounded wildcard is reifiable only in that no type information is lost at runtime because there's no type information to lose. As to your questions:

    a. The test method doesn't know that l2 has Integer type. To the test method, it's a List containing "something", and that's all.

    b. There's no "translation". It's just a list of unbounded type passed as a parameter to a method that takes a list of unbounded type.

提交回复
热议问题