Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import package as another

Let's say I have a Scala project with a bunch of case classes under package com.example.a.b.c. I want to import all these classes into a package com.example.c (which contains a few more non-conflicting case classes) so that anywhere else in my project, I only need to import com.example.c._ to use every case class both from com.example.c and com.example.a.b.c.

How can I do that?

like image 756
user510159 Avatar asked Dec 11 '12 22:12

user510159


1 Answers

There is discussion of adding an export mechanism which would do what you want, but it's not clear whether that will happen.

In any case, for now the only way is to

  • Define the type of every class
  • Set a val equal to every object

So for example,

package bar
case class Foo(i: Int) {}

would need to be mimicked in another package with

package object baz {
  type Foo = bar.Foo
  val Foo = bar.Foo
}

When faced with this, people usually just settle for an extra import or two.

like image 194
Rex Kerr Avatar answered Sep 28 '22 02:09

Rex Kerr