Home > Java > javaTutorial > What issues to pay attention to: Things to note when using Java functional interfaces

What issues to pay attention to: Things to note when using Java functional interfaces

WBOY
Release: 2023-04-22 22:28:14
forward
1228 people have browsed it

Concept

#1. Functional interface only contains the declaration of an abstract method. All types of Lambda expressions will match this abstract method.

Usage Notes

2. As long as the interface only contains one abstract method, we can rewrite it as a Lambda expression. In order to ensure that the interface is clearly defined as a functional interface (Functional Interface), we need to add annotation: @FunctionalInterface to the interface. This way, the compiler will throw an error as soon as you add the second abstract method.

Example

@FunctionalInterface
interface Converter<F, T> {
    T convert(F from);
}
Copy after login

What are the advantages of Java

1. Simple. As long as you 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 carry out memory management and prevent programmers from making mistakes 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 Java bytecode.

The above is the detailed content of What issues to pay attention to: Things to note when using Java functional interfaces. 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