What is the difference between scala classes, scripts and worksheets in Intellij-idea?

前端 未结 2 2024
南笙
南笙 2021-01-01 15:26

I\'m using Intellij-idea for scala programming (with sbt plugin).

I want to know what is the difference between scala classes, scala scripts and scala worksheets. Wh

2条回答
  •  忘掉有多难
    2021-01-01 16:19

    Scala Worksheet

    It's the same as Scala Interpreter (REPL) but runs inside IntelliJ. Where you may easily and quickly evaluate some expressions. Check IntelliJ confluence page for more information.

    Scala Script

    If you don't want write script on Bash you can do it with Scala. It's just sequence of Scala statements.

    Example:

    import java.nio.file.{Paths, Files}
    
    val ScalaSource = "*.scala"
    val Path = "path/to/necessary/folder"
    
    val stream = Files.newDirectoryStream(Paths.get(Path), ScalaSource)
    
    val paths = stream.iterator
    while (paths.hasNext) {
      println(paths.next.getFileName)
    }
    

    Running it:

    $ scala scala_script_name.scala
    

    To getting started pick up this guide.

    Classes & Object

    Short answer for Scala classes it's similar to POJO and Scala Objects it's a Java Singleton class.

提交回复
热议问题