You have a method that expects an object of type X. To pass an object to this method, this object must have a type Ythat is a subtype X.
:
void processNumber(Number number) { ... }
void callIt()
{
Integer integer = null;
processNumber(integer);
String string = null;
processNumber(string);
}
. . : - ?:
, , FAQ.
, (), , .
, , , . , , , Map<String, List<String>>, , T String . T String, . ( , )
, , , . : , , . :
Map<String, List<String>> Map<String, List<?>>
( ) , :
Map<String, List<String>> map = new HashMap<>();
Map<String, List<?>> otherMap = map;
, " " FAQ, , , , , : A Map<String, List<?>> - , , / . , processMap1:
public void processMap1(Map<String, List<?>> map)
{
List<Number> numbers = new ArrayList<Number>();
map.put("x", numbers);
}
, Map<String, List<String>> :
public void f() {
Map<String, List<String>> map = new HashMap<>();
processMap1(map);
List<String> shouldBeStrings = map.get("x");
}
ClassCastException, Map<String, List<String>> , List<Number> .
: , .
( , , ):
T . ?, , , . reverse rev , T - ?, , . , :
List<T> List<?> ( , T)
processMap1 processMap2 , : Y X, Map<String, Y> Map<String, X>. .