Home > Java > JavaBase > The difference between method reference and method call in java

The difference between method reference and method call in java

王林
Release: 2019-11-16 14:45:32
Original
4628 people have browsed it

The difference between method reference and method call in java

Method reference:

The method reference returns the implementation of the interface.

  private static <T> Iterable<T> itToIterable(Stream<T> stream) {
        return stream::iterator; //编译通过此处返回的是Iterable
  }
Copy after login

Method call:

Method call returns the return value of the method.

    private static <T> Iterable<T> itToIterablePro(Stream<T> stream) {
        return stream.iterator(); //编译失败此处返回的是iterator
    }
Copy after login

Recommended tutorial: Java tutorial

The above is the detailed content of The difference between method reference and method call in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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