Why scala's pattern maching does not work in for loops for type matching?

后端 未结 3 812
盖世英雄少女心
盖世英雄少女心 2020-12-10 15:25

I\'m coding against an API that gives me access to remote file system. The API returns a list of files and directories as list of node objects (parent to file and directory)

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 16:12

    How about this:

    val listOfBaseObjects: List[Any] = List[Any]("a string", 1:Integer);
    
    for (x <- listOfBaseObjects if x.isInstanceOf[String]) {
      println(x)
    }
    

提交回复
热议问题