I have read O'Reilly book, in that I came to know this get-put principle.
- Use an
extends
wildcard when you only get values out of a structure.- Use a
super
wildcard when you only put values into a structure.- And don't use a wildcard when you both want to get and put from/to a structure.
Exceptions are:
You cannot put anything into a type declared with an
extends
wildcard except for the valuenull
, which belongs to every reference type.You cannot get anything out from a type declared with an
super
wildcard except for a value of typeObject
, which is a super type of every reference type.
Can anyone help me to explore this rule at depth? If possible, please put them hierarchical manner.