[英]Java 8 Method expression is giving compilation error
I am new to Java 8 (Lambda Expression). 我是Java 8(Lambda Expression)的新手。 The following piece of code prints all the directories at the path indicated by the variable "file".
下面的代码打印变量“file”指示的路径上的所有目录。
File file = new File("/vssexclude/Test/workspace/Test");
File[] names = file.listFiles(fileName -> fileName.isDirectory());
for (File name : names) {
System.out.println(name.toString());
}
But, when I try to replace the lambda expression with method expression, eclipse is giving compilation error: 但是,当我尝试用方法表达式替换lambda表达式时,eclipse会给出编译错误:
File[] names = file.listFiles(File::isDirectory());
What am I missing? 我错过了什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.