Is there a way in the Scala REPL to set the "active" package scope ? Say I have a package com.package
with class A
, I want to be able to type new A()
instead of new com.package.A()
without explicitly doing import com.package.A
. There might be a number of other classes in that package I'm interested into and I don't want to polute my REPL's global namespace by doing import com.package._
.
Even better, I'd like to define class A without typing its fully qualified name. Something like:
package com.package // do this once
class A
class B
val a = new A()
val b = new B()
I'm aware of the :paste -raw
command, but that would require me to type package com.package
for each block; I'm really looking for a stateful command to change the "current working package", if you will.
Simply put, you cannot.
Each command in the scala REPL is wrapped into a newly generated package, as explained here.
Also, there was a ticket asking package { }
support in the REPL, but it was dismissed as :paste -raw
was considered enough for the purpose.
来源:https://stackoverflow.com/questions/25343217/setting-package-in-scala-repl