Home  >  Article  >  Java  >  What are the concepts and usage of Java generics?

What are the concepts and usage of Java generics?

王林
王林forward
2023-04-27 15:16:071556browse

Concept

1. Generics means that types can be passed as parameters, which are essentially type parameters. For example, when we define a method, we often specify that a specific class of objects be passed as parameters.

2. If generics are used, a specific transfer object can be specified as a specific type without specifying a specific type. That is, we pass a certain type as a parameter.

Difference from Object

If you use Object, you must force the input type to be converted to the required type. If the input type does not match, it will cause the package ClassCastException. abnormal. For example, in the following code, testObj() inputs a value of type int, and an error occurs when the program is executed:

Example

public void testObj(Object o){
    String name= (String) o;
}

What are the commonly used java frameworks

1.SpringMVC, Spring Web MVC is a lightweight Web framework based on Java that implements the request-driven type of Web MVC design pattern.

2.Shiro, Apache Shiro is a security framework for Java.

3.Mybatis, MyBatis is an excellent persistence layer framework that supports ordinary SQL queries, stored procedures and advanced mapping.

4.Dubbo, Dubbo is a distributed service framework.

5.Maven, Maven is a project management and build automation tool.

6.RabbitMQ, RabbitMQ is a high-concurrency and high-reliability AMQP message queue server implemented in Erlang.

7.Ehcache, EhCache is a pure Java in-process caching framework.

The above is the detailed content of What are the concepts and usage of Java 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