You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This program tests the Wildcard operator (?) for generic classes.
It is used to receive any type, restrict to superclasses, and to make variables read-only
*/
import java.util.List;
import java.util.ArrayList;
public class Wildcard {
public static void main(String args[]) {
ArrayList<Integer> readOnlyList = new ArrayList<>();
readOnlyList.add(1);
readOnlyList.add(3);
Wildcard.method(readOnlyList);
// Thing<?,? extends Number> thing = new Thing<String,String>(new String("cosa"), new String("nnn")); // DOESN'T WORK, SECOND TYPE SHOULD BE NUMBER OR SUBTYPE
Thing<?,? extends Number> thing = new Thing<String,Integer>(new String("cosa"), new Integer(8));