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

What are java pseudo-generics?

PHPz
Release: 2023-05-21 15:10:35
forward
1680 people have browsed it

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
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template