Classes in Worksheet in Scala-IDE cause error

时光毁灭记忆、已成空白 提交于 2019-12-10 15:38:55

问题


Just instantiating a class by typing the following into a Worksheet (note, Worksheet, created with File > New > Scala Worksheet, a .sc file, not a normal .scala file) and clicking Save causes a spurious error:

Mouseover:

"Multiple markers at this line - illegal start of simple expression - ';' expected but identifier found."

I doubt something as simple as this could have slipped through testing so maybe it's a configuration issue. I've tried it on 2 machines and get the same behaviour:

1) Windows 7 with Eclipse Helios

2) Windows XP with Eclipse Indigo - clean download from Typesafe website

Any ideas? Do other people get this on their setup?


回答1:


This bug was fixed in the Scala compiler, but the fix is not in the version shipped with the milestone release.

If you update to a nightly build of the Scala IDE, you should be able to use this code pattern.




回答2:


During the Martin Odersky lectures on Coursera I noticed that he declares his classes outside the main object in his workbooks.

I hope this helps

object Worksheet {
  new Foo
}

class Foo


来源:https://stackoverflow.com/questions/12736485/classes-in-worksheet-in-scala-ide-cause-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!