C # generics do not have a type wildcard because. NET generics are generics supported by the CLR, and Java's JVM does not support generics, just syntax sugar, which is converted to type object at compiler compile time
Type Wildcard in Java represents the parent class of a generic type
public void Test (list<object> c) {for (int i = 0;i < C.size (); i++) { System.out.println (c.get (i)); } }
Create a List<string> object list<string> strlist = new arraylist<string> (); The previous test method test (strlist) is invoked with Strlist as a parameter;
Compile the above program, test (Strlist) will have a compile error, meaning that list<string> can not be considered as a subclass of list<object>. This is the time to use the type wildcard, the wildcard is a number
The above list<object> replaced with list<?> to be able to compile the
public void Test (list<?> c) {for (int i = 0;i < C.size (); i++) { System.out.println (C.get (i)); } }
List<string> can be used as a subclass of List<?>, list<?> can be used as a parent of whatever List type,
Suppose you just want to be the parent of list<string>, not list<int>? Written such list<?
Extends string>
Constraining the generic type in C # is like this
Class Myclass<t, u> where T:class where u:struct {}
Interface IMyInterface { } class Dictionary<tkey, tval> where tkey:icomparable, IEnumerable where Tval:imyinterface {Public void Add (TKey key, Tval val) { } }
upper bound generic wildcard characters in Java:
Indicates that the T type must be a number class or its subclass, and must implement the Java.io.Serializable interface public class Apple<t extends number & Java.io.serializable> {}
Java, generic type wildcard and C # control