lamda表达式无法识别的问题

lyfuci 2017-01-03 06:28:57

@FunctionalInterface
public interface FilenameFilter {
/**
* Tests if a specified file should be included in a file list.
*
* @param dir the directory in which the file was found.
* @param name the name of the file.
* @return <code>true</code> if and only if the name should be
* included in the file list; <code>false</code> otherwise.
*/
boolean accept(File dir, String name);
}

这是一个jdk的原生类,然后想用lamda表达式来得到目录中满足条件的文件列表,关键代码如下
File[] subFiles=file.listFiles((file,".")->{ return true;});

但是编译器无法识别。错误提示如下

下面试验了一下用lamda表达式的简单输出没有问题。不知道到底这个是什么原因不能识别。
...全文
270 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lyfuci 2017-01-03
  • 打赏
  • 举报
回复
貌似就是参数必须是变量名,而且不能内部声明。
lyfuci 2017-01-03
  • 打赏
  • 举报
回复
自己顶一下!!!

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧