I have a strange behaviour in the eclipse IDE.
I reproduced it with the documentation on package objects
I have a file
src/main/scala/gardening/fruits/Fruit.scala
containingpackage gardening.fruits
case class Fruit(name:String)
object apple extends Fruit("Apple")
object plum extends Fruit("Plum")
a file
src/main/scala/gardening/fruits/package.scala
containingpackage gardening
package object fruits { val planted = List(apple, plum)
def showFruit(fruit: Fruit) { println(fruit.name +"s are ") } }a scala worksheet in
src/main/scala/fruitws.sc
containingimport gardening.fruits._
object PrintPlanted { def main(args: Array[String]) { for (fruit: Fruit <- fruits.planted) { showFruit(fruit) } } }
Now :
- eclipse says "can't find gardening" (and of course
fruits
andFruit
) - if I hit
ctrl space
after placing a dot after gardening, some autocompletion appears though - stranger, one of those completion is called gardeningfruits (so as a child of gardening, with no dots...)
What am I doing wrong that prevents the worksheet to execute properly ?
edit
I think the package object idea is not available in worksheet.
As a separate point, worksheet might mandate some file organisation on disk that scala files themselves escape (aka, having a file in gardening/fruit/fruit.scala and package gardening only in the file). Not sure..