Home  >  Article  >  Java  >  Summary of articles about generics

Summary of articles about generics

零下一度
零下一度Original
2017-06-12 11:35:211429browse

Introduction Generics are a very important knowledge point in Java. Generics are widely used in the Java collection class framework. In this article, we will look at the design of Java generics from scratch, which will involve wildcard processing and annoying type erasure. Generic basics Generic class We first define a simple Box class: public class Box { Private String object; Public void set(String object) { this.object = object; } public String get()

1. Java generics explanation

Summary of articles about generics

##Introduction: Generics are a very important knowledge point in Java. Generics are widely used in the Java collection class framework. In this article, we will look at the design of Java generics from scratch, which will involve wildcard processing and annoying type erasure.

2. Summary of Java Generics (1) - Detailed explanation of basic usage and type erasure

Summary of articles about generics

Introduction: This article mainly introduces the use of Java generics and issues related to type erasure. Has very good reference value. Let’s take a look with the editor below

3. Java Generics (Generics) Overview Sample Code Detailed Explanation

Summary of articles about generics

Introduction: Java generics are a new feature introduced in JDK 5 that allow the use of type parameters when defining classes, interfaces and methods. General classes and methods can only use specific types. If you want to write code that can be applied to multiple types, this rigid restriction will be very restrictive to the code. Polymorphism is a generalization mechanism, but the constraints on the code are still too strong. There are many reasons for the emergence of generics, but one of the most compelling reasons is to create container classes. As a review article of generics, this article comprehensively explains the motivation, basic concepts, implementation mechanism, type erasure, use of wildcards, covariance and contravariance of generics.

4. Java Generics - Type Erasure

Introduction: There are many problems in using Java generics Problems such as List.class does not exist, List cannot be assigned to List (not covariable), strange ClassCastException, etc. The correct use of Java generics requires an in-depth understanding of some Java concepts, such as covariance, bridging methods, and type erasure as documented in this note. Java generics are almost all processed in the compiler. The bytecode generated by the compiler does not contain generic information. The generic type information will be erased during compilation. This process is called type erasure.

[Related Q&A recommendations]:

java - Is String a subtype of Comparable?

Java Core Technology The section "Type variables are invalid in the static context of a generic class" in the chapter on generics in Volume 1 cannot be understood

The above is the detailed content of Summary of articles about generics. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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