mane
mane

Reputation: 1179

If scala case class and object have same name, how to import case class only

Well I have a scala class Foo.scala containing these two elements,

First One,

case class Foo(
.
.
.
)

And secondly,

object Foo{
.
.
.
}

Now when I import the Foo in some other file, I want to use the case class not the Object, but when I import the file, object instance is returned in Foo<= this is the object,(I needed to do Foo.apply, Foo.tupled)

Is there anyway I can get the Foo to act as the case class then an object.

Upvotes: 0

Views: 2729

Answers (2)

Uraniium
Uraniium

Reputation: 109

you can try this

 (Foo.apply _).tupled

Upvotes: 0

Chris Stewart
Chris Stewart

Reputation: 1689

You have ambiguity in your scala namespaces. A simple solution to the problem would be to nest the case class inside of the object, then import it with

import Foo.Foo

another solution would be to place them in separate packages. Depending on your system design this could affect the cohesiveness of your packages, which in my mind is probably more important.

Upvotes: 0

Related Questions