2012-03-02 60 views
0
匿名類

我想使用NIO.2功能使用Scala(類是java.nio.file):實現靜態內部接口Scala的

在Java中,我會做:

​​

我該如何在Scala中做同樣的事情? FitlerDirectoryStream接口內部的靜態接口。

謝謝。

編輯:請不要回復,如果你想建議我另一個庫/方法列出文件。我主要關心的主要問題。

回答

5

不是100%確定是否你所要求的驗證碼Scala中的文字轉換:

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 2012-03-02 14:09:12