Scala giving me “illegal start of definition”

后端 未结 5 479
死守一世寂寞
死守一世寂寞 2020-12-13 16:48

I\'m trying to get started with Scala and cannot get out of the starting gate.

A file consisting of the line

package x

gives me

5条回答
  •  醉梦人生
    2020-12-13 17:46

    I had the same issue when I was executing scala program eg. "Game.scala" from terminal.

    Compiling part was ok, error was shown when running the code, see below

    ☐ Wrong:

    user@pc:~$scala Game.scala
    /home/$USER/.../src/ul/org/bloxorz/Game.scala:1: error: illegal start of definition
    package ul.org.bloxorz
    
    

    Scala code should be invoked from terminal pretty much the same as Java code (you should give it a fully qualified class name and not the file name like I did in first example)

    ☑ Correct:

    user@pc:~$scala ul.org.bloxorz.Game
    
    

提交回复
热议问题