Understanding upper and lower bounds on ? in Java Generics

后端 未结 6 484
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 01:45

I am really having a tough time understanding the wild card parameter. I have a few questions regarding that.

  1. ? as a type parameter can only

6条回答
  •  一生所求
    2020-11-29 02:13

    Hmmmm your statement on super ( printAll(MyList) ) is not clear. What it means, assuming Myclass extends Object is that you can printAll(MyList) and you can printAll(MyList) but nothing else.... it means that the generic type of MyList has to be a superclass (not a subclass) of MyClass. This is different to what you said.

    As for the T, E, K, V, or N, well, these are meaningless names in and of themselves. You can use anything you want. Convention suggests single-letter upper-case values though, and T is often used for generic methods, and E for classes....

    提交回复
    热议问题