Suppose my project has package org.abc
with several Scala files inside. All the Scala files contain the same import
statements, e.g. import org.x._
, import org.y._
, import org.z._
I don't like the repetition. Can I move all these import
statements to one single file ?
You can use the same pattern that is used in scala/package.scala: create an org.abc
package object
with a type
and a val
for each definitions you want to import from org.{x, y, z}._
:
package org
package object abc {
type Maybe[A] = org.x.Maybe[A]
val Maybe = org.x.Maybe
type MyClass = org.y.MyClass
val MyClass = org.y.MyClass
}
yes you can, by using package objects
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With