Is there a way to avoid entering integer package names in the Scala interpreter in Eclipse?

I am currently writing a project in Scala in Eclipse, and this is a real problem when I need to enter whole package names to get to the classes I wrote. For instance:

If I write the Sender class in the package com.ab.cd.ef.gh, then whenever I try to use this object, I should do something like:

val sender = com.ab.cd.ef.gh.Sender.getSender 

or something similar. Is there a way to set the interpreter so that I only need to type

 val sender = Sender.getSender 

?

+4
source share
2 answers

use import com.ab.cd.ef.gh._ to import the entire package. See here for more details on scala import statements.

+6
source

As already mentioned, you can use import to import data into repl.

To avoid importing the same material every time you reboot, you can place your common imports and definitions in a file, say imports.scala and preload this file in repl with -i .

 ✗ cat imports.scala import collection.mutable.HashSet ✗ scala -i imports.scala Loading imports.scala... import collection.mutable.HashSet Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26). Type in expressions to have them evaluated. Type :help for more information. scala> HashSet(1, 2) res0: scala.collection.mutable.HashSet[Int] = Set(2, 1) 
+6
source

All Articles