Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use java built-in functional interface

Shulou Source: shulou.com Published: 2022-05-31 17:49:16 09月30日 Update

This article mainly explains the "java built-in functional interface how to use", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "java built-in functional interface how to use" it!

1. Predicate is a Boolean function with only one input parameter. The Predicate interface contains a variety of default methods to handle complex logical verbs.

Predicate predicate = (s)-> s.length () > 0; predicate.test ("foo"); / / truepredicate.negate () .test ("foo"); / / false Predicate nonNull = Objects::nonNull;Predicate isNull = Objects::isNull; Predicate isEmpty = String::isEmpty;Predicate isNotEmpty = isEmpty.negate ()

2. The Function interface receives a parameter and returns a single result. By default, multiple functions can be concatenated together.

Function toInteger = Integer::valueOf;Function backToString = toInteger.andThen (String::valueOf); backToString.apply ("123"); / /" 123"

3. The Supplier interface produces results of a given type. Unlike Function,Supplier, there are no input parameters.

Supplier personSupplier = Person::new;personSupplier.get (); / / new Person Thank you for reading, this is the content of "how to use java built-in functional interface". After the study of this article, I believe you have a deeper understanding of how to use java built-in functional interface, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Interfaces functions parameters learning content situation results input complexity verbs single only multiple multiple that is Boolean ideas articles methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MariaDB vpn Shulou Tech Info macOS