If T both inherits the class and specifies the interface, use the following method:
public class Some<t extends Iterable<t> & comparable<t>>{}
Java generics do not have a covariance (if B is a subclass of a, and node<b> can be considered a node<a>, then node has a covariance), but you can use a type wildcard character? and extends to declare the variable so that it achieves a similar covariance.
node<apple> Apple = new Node<> (new Apple (), null); node<? Extends fruit> Fruit = Apple; Similar to the effect of co-degeneration; if node<fruit> Fruit = Apple; The compilation error will be
If the statement does not matchextends, the default is? extends Object, such as:
Node<?> fruit = null; Equivalent to <span style= "font-family:arial, Helvetica, Sans-serif;" >node<? Extends object></span>
Note: this differs from the declaration node<object>, if it is declared as Node<object>, then only reference to node<object> Instance , the following program compiles an error:
node<object> node = new node<integer> (1, null); No co-degeneration
Should be:
node<?> node = new node<integer> (1, NULL);
Once used? With the extends limit the type of T, you can only get the object by the name of the T declaration or specify the name of the T declaration as null, in addition to other specified actions
node<? Extends fruit> Fruit = new node<> (new Apple (), null), Object o = Node.value;node.value = null; Apple Apple = node.value; Compilation Error Node.value = Apple Apple (); Compile error
The above program only knows if the object type of value reference will be inherited fruit, but will it actually be apple or banana? If Node.value is actually an instance of banana, it is wrong to assign Apple type to Apple
Other:
Java's generic syntax is only checked at compile time, unknown at execution time, and actually only known as the object type (also known as "type Erasure"), such as:
List<integer> List1 = new arraylist<> (); list<string> list2 = new arraylist<> (); System.out.println (List1.equals (List2)); Output true
Java Learning notes-generics