Reputation: 169
I have defined a type inside a package object as following in package.scala.
type Structure = List [(int, int)]
Now I want to use this Structure inside a class in abc.scala and get the elements of the list individually. abc.scala and package.scala are inside the same folder (src/utility).
class abc (d: Structure) {
val a = d._1
val b = d._2
...................
...................
}
It compiles, but I need to try a test inside another folder (test). I have imported the package utility in the test code as follows.
import utility._
class test {
val a = utility.Structure ((1, 2), (2, 5))
............................
............................
}
I am getting the following error:
object Structure is not a member of package src.utility.
Note: type Structure exists, but it has no companion object.
How do I define the companion object of the type? I need to use the type in the class abc.
Upvotes: 3
Views: 3220
Reputation: 217
So, it sounds like you have something like this:
package src
package object utility {
type Structure = List[(Int, Int)]
}
To get what you want, simply add val Structure = List
. So, it'd look like this:
package src
package object utility {
type Structure = List[(Int, Int)]
val Structure = List
}
Now, Structure((1, 2))
will work as long as you import your package.
Upvotes: 3