1. Notes
Generic methods can exist in either generic classes or ordinary classes. If using generic methods can solve the problem, then you should try to use generic methods.
The type parameter T in the generic method and the type parameter in the generic class are of different types.
2. Example
//注意这个T是一种全新的类型,可以与泛型类中声明的T不是同一种类型。 public <T> void PrinterInfo(T e) { System.out.println(e); } //调用方法 DataHolder<String> dataHolder=new DataHolder<>(); dataHolder.PrinterInfo(1); dataHolder.PrinterInfo("AAAAA"); dataHolder.PrinterInfo(8.88f);
Collections in Java are mainly divided into four categories:
1 , List list: ordered, repeatable;
2, Queue queue: ordered, repeatable;
3, Set collection: non-repeatable;
4. Map mapping: unordered, unique keys, but not unique values.
The above is the detailed content of What should you pay attention to when using java generic methods?. For more information, please follow other related articles on the PHP Chinese website!