What's the difference between class<t> and class<?> types?
T
object is the root class of all classes, a specific class, which may require type casts, but with T. When this is done, the type is determined before it is actually used, and no casting is required.
Ask:
In other words, this method can know which type (parent) to return, and use T to do it. Use it if you don't know it at all. The object obtained with T is not required for type conversion. Must be used with a strong turn.
Chase Answer:
The first is a fixed generic, and the second is as long as subclasses of the object class can, in other words, any class can, because object is the base class of all classes
Fixed generic reference types are fixed, such as: Interge,string. It's <t. Extends Collection>
<. Extends collection> here. Represents an unknown type,
However, this unknown type is actually a subclass of collection, and collection is the upper bound of the wildcard character.
For example
Class Test <t extends Collection> {}
<t extends collection>, where T is a certain type (concrete type) when constructing instances of this class. This type implements the collection interface,
But there are a lot of classes that implement the collection interface, and if you want to write specific subclass types for each one, that's too much trouble, and you might as well use the
object for general purposes.
The extends collection> of which,? is an unknown type, is a wildcard generic, this type is the implementation of the Collection interface.
_________________________ What ghosts are above, when you know the origin of the wildcard generics (the following code is provided by java1234.com) _______________________________ __________________________________________________________
The method take (Animal) in the type Test isn't applicable for the arguments (demo<dog>)
The method take (Animal) in the type Test isn't applicable for the arguments (demo<cat>)
The method take (Animal) in the type Test isn't applicable for the arguments (demo<animal>)
When generics are introduced, it is not appropriate for parameters to be written, and there are 2 methods that do not apply, and in order to write a generic method for generic classes, this is the time to introduce them. The concept of wildcard characters.
public class Demo <t extends animal>{
private T ob;
Public T Getob () {return
ob;
}
public void Setob (T ob) {
this.ob = ob;
}
Public Demo (T ob) {
super ();
THIS.OB = OB;
}
The type of public void print () {
System.out.println ("t) is:" +ob.getclass (). GetName ());
}