小编And*_*ndy的帖子

可作为方法参考运行

为什么这段代码不能编译?无法完全掌握 java 方法参考的细微差别:(

public class TestClass {

    static void println() {}
    
   public static void main(String[] args) {

        Runnable r1 = () -> System.out::println; // compilation error
        Runnable r2 = () -> TestClass::println;  // compilation error
        Runnable r2 = () -> System.out.println("Hello World");  // This is fine !!

    }
}
Run Code Online (Sandbox Code Playgroud)

java lambda java-8 method-reference

3
推荐指数
1
解决办法
132
查看次数

标签 统计

java ×1

java-8 ×1

lambda ×1

method-reference ×1