Home >Java >javaTutorial >What are java pseudo-generics?

What are java pseudo-generics?

PHPz
PHPzforward
2023-05-21 15:10:351686browse

Explanation

1. Generics in Java are pseudo-generics. This method of implementing generics is called type erasure, and generics implemented based on this method are called pseudo-generics.

2. Since Java's generics only play a role in the compilation phase, they play a role in checking when writing code.

When the code runs, there are no generics inside it.

Example

List<String> l1 = new ArrayList<String>();
List<Integer> l2 = new ArrayList<Integer>();
System.out.println(l1.getClass() == l2.getClass()); //true

The result is true, the Class of List and List in jvm are both List.class, that is, the generic information is erased Apart from.

What collection classes are there in Java?

Collections in Java are mainly divided into four categories:

1. List: ordered, repeatable;

2. Queue: ordered and repeatable;

3. Set: non-repeatable;

4. Map: unordered, with unique keys and non-unique values.

The above is the detailed content of What are java pseudo-generics?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete