erikreppel
erikreppel

Reputation: 81

Is it possible to import all variable from an object?

If I have an object in a package is it possible to import and execute all commands from another package? Ex:

object Example {
  val fakeMap: Map[Int, Int] = Map()
  fakeMap += (0 -> 1)
  def aFunction(a: Map) = {
    a += (1 -> 2)
    return a
  }
}

is it possible to automatically execute creating fakeMap and adding the value, other than:

import package.Example

val aMap = Example.fakeMap
val newMap = Example.aFunction(aMap)

Upvotes: 2

Views: 2269

Answers (1)

Sekkuar
Sekkuar

Reputation: 386

What you need is a wildcard import:

import package.Example._

(In Java, you'd use import static for the same thing.)

This will import all members of the Example object, so you can invoke them without referencing the class name:

val aMap = fakeMap
val newMap = aFunction(aMap)

Upvotes: 5

Related Questions