Monday, October 19, 2015

what is difference between < ? super T > and < ? extends T >

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).

 

No comments:

Post a Comment

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...