Reputation: 9805
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
containing
package 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
containing
package 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
containing
import gardening.fruits._
object PrintPlanted { def main(args: Array[String]) { for (fruit: Fruit <- fruits.planted) { showFruit(fruit) } } }
Now :
fruits
and Fruit
)ctrl space
after placing a dot after gardening, some autocompletion appears thoughWhat 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..
Upvotes: 1
Views: 2423
Reputation: 2831
You need to compile .scala
files before you can import them into worksheet
Upvotes: 4