what is difference between < ? super T> and <? extends T> ?
<? super T> :
Here the ? is a wildcard which represents the parameter type. (i.e List<Integer> here Integer is a parameter type), T is a generic Type and super is a keyword which represents the put principle.
If it is List<? super T> then one can put all the types objects into this list which comes int the range of ? and T.
because of the usage of super one cannot get the values from this list.
<? extends T>:
Here the ? is a wildcard which represents the parameter type. (i.e List<Character> here Character is a parameter type).
T is a generic type (i.e public static <T> void getList(T[] arr); here T is a generic type)
and extends is keyword. and the pattern <? extends T> represets the get principle of generic.
means if it is List<? extends T> then one can get the values from this list. and the value object will be ranging between the ?(TYPE) and T(type).
<? super T> :
Here the ? is a wildcard which represents the parameter type. (i.e List<Integer> here Integer is a parameter type), T is a generic Type and super is a keyword which represents the put principle.
If it is List<? super T> then one can put all the types objects into this list which comes int the range of ? and T.
because of the usage of super one cannot get the values from this list.
<? extends T>:
Here the ? is a wildcard which represents the parameter type. (i.e List<Character> here Character is a parameter type).
T is a generic type (i.e public static <T> void getList(T[] arr); here T is a generic type)
and extends is keyword. and the pattern <? extends T> represets the get principle of generic.
means if it is List<? extends T> then one can get the values from this list. and the value object will be ranging between the ?(TYPE) and T(type).
No comments:
Post a Comment