Home >Java >javaTutorial >How to reference methods in java8

How to reference methods in java8

WBOY
WBOYforward
2023-05-22 10:52:061538browse

1. Constructor method reference

Test test = Test.create(Test::new);

2. Static method reference

test.operate(1, 2, Test::add);

3. Object instance Method reference

test.operate(1, 2, test::sub);

4. Instance method reference of the class, satisfies the instance method first, not the static method.

The first parameter of the Lambda expression will become the object of the calling instance.

test.test(Test::testM);

The above is the detailed content of How to reference methods in java8. 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