2012-03-02 5 views
0
익명 클래스와 정적 내부 인터페이스를 구현

나는 (클래스 java.nio.file에) 스칼라와 NIO.2 기능을 사용하고 싶습니다 :스칼라

자바에서

내가 할 것 :

Files.newDirectoryStream(Paths.get("/tmp"), new DirectoryStream.Filter<Path>() { 
    @Override 
    public boolean accept(Path entry) throws IOException { 
    return false; 
    } 
}); 

스칼라에서 어떻게 똑같이 할 수 있습니까? FitlerDirectoryStream 인터페이스의 정적 인터페이스입니다.

감사합니다.

편집 : 파일을 나열하는 다른 라이브러리/방법을 제안하고 싶다면 답장을 보내지 마십시오. 저는 주로 주요 문제에 관심이 있습니다. 당신은 스칼라에서이 코드의 문자 변환을 요청 여부를 확인

답변

5

100 % : 다른

Files.newDirectoryStream(Paths.get("/tmp"), new DirectoryStream.Filter[Path] { 
    def accept(entry: Path) = false 
}) 

.. 또는 뭔가?

class PathPredicateFilter(p: Path => Boolean) 
    extends DirectoryStream.Filter[Path] { 
    def accept(entry: Path) = p(entry) 
} 
implicit def PathPredicate_Is_DirectoryStreamFilter(p: Path => Boolean) 
    = new PathPredicateFilter(p) 

지금 당신은이 작업을 수행 할 수 있습니다 :

Files.newDirectoryStream(Paths.get("/tmp"), (p: Path) => false /* your code here */) 
+0

제기랄 당신은 암시 적 변환을 추가 할 수 있습니다. 네, 가능한 모든 구문 조합을 시도하고 굉장히 봤다고 생각하기 때문에 저는 문자 그대로의 변환을 원했습니다. 고맙습니다. – woky