Home  >  Article  >  Java  >  How to define an interface with generics in Java?

How to define an interface with generics in Java?

王林
王林forward
2023-05-07 09:31:071184browse

1. You can define an implementation class to implement ICall. If you do not specify the generic type when defining the MethodCall class, you will be prompted with a compilation error during compilation.

2. When implementing a generic interface class to pass a specific type, the interface method should also be modified to a specific type at this time.

Example

public class MethodCall<String> implements ICall<String> {
 
    @Override
    public String exec(Param param) {
        Object object = new ArrayList<>();
        return null;
    }
}

What are the advantages of Java

1. Simple, just understand the basic concepts, you can write programs suitable for various situations Application;

2. Object-oriented;

3. Distribution, Java is a network-oriented language;

4. Robustness, java provides automatic garbage collection To perform memory management and prevent programmers from making errors when managing memory;

5. Security, Java used in network and distributed environments must prevent virus intrusion.

6. Architecture neutral, as long as the Java runtime system is installed, it can run on any processor.

7. Portability, Java can be easily transplanted to different machines on the network.

8. Interpretation and execution, the Java interpreter directly interprets and executes the Java bytecode.

The above is the detailed content of How to define an interface with generics in Java?. 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