作为将Java代码转换为Scala代码的努力的一部分,我需要将Java流转换Files.walk(Paths.get(ROOT))为Scala.我无法通过谷歌搜索找到解决方案.asScala不会这样做.任何提示?
以下是相关代码:
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Collectors;
....
Files.walk(Paths.get(ROOT))
.filter(path -> !path.equals(Paths.get(ROOT)))
.map(path -> Paths.get(ROOT).relativize(path))
.map(path -> linkTo(methodOn(FileUploadController.class).getFile(path.toString())).withRel(path.toString()))
.collect(Collectors.toList()))
Run Code Online (Sandbox Code Playgroud)
Files.walk(Paths.get(ROOT))返回类型是Java中的Stream.
我有一个方法最初返回单位.将返回类型更改为Future [Unit]后,我找不到更改方法体的方法.最少的一行是方法调用.
在以下代码段中,
val line = ... // a list of String array
line match {
case Seq("Foo", ... ) => ...
case Seq("Bar", ... ) => ...
...
Run Code Online (Sandbox Code Playgroud)
我将上面的代码更改为以下内容:
object Title extends Enumeration {
type Title = Value
val Foo, Bar, ... = Value
}
val line = ... // a list of String array
line match {
case Seq(Title.Foo.toString, ... ) => ...
case Seq(Title.Bar.toString, ... ) => ...
...
Run Code Online (Sandbox Code Playgroud)
而且,我收到一个错误:
stable identifier required, but com.abc.domain.enums.Title.Foo.toString found.
Run Code Online (Sandbox Code Playgroud)
在 case 语句中替换字符串的正确方法是什么?