0

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.

mane
  • 1,149
  • 16
  • 41
  • Is their any possibility that you can change name of any one either of **case class** or **object**? – Uraniium Aug 06 '14 at 11:49
  • No can't do, can't change the object/case class name since I am working with legacy code, so don't know where else my change would affect the codebase. – mane Aug 06 '14 at 11:52
  • 1
    is this similar to http://stackoverflow.com/questions/22367092/using-tupled-method-when-companion-object-is-in-class ? – Shyamendra Solanki Aug 06 '14 at 11:54
  • Yup, t'was similar, thanks for the link @shyamendra-solanki, it helped a lot. – mane Aug 06 '14 at 12:01

2 Answers2

0

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.

Chris Stewart
  • 1,641
  • 2
  • 28
  • 60
  • Yes, case class and object name should not have been the same , and its a legacy code not my work, so I cant change their positions, like you have suggested. – mane Aug 06 '14 at 11:51
  • If you can't change their position that must mean some one else is dependent upon the import, which implies that some one had already figured out how to import the case class instead of the object? – Chris Stewart Aug 06 '14 at 11:59
  • seems like there is an solution to my problem, solutions in this link ===> http://stackoverflow.com/questions/22367092/using-tupled-method-when-companion-object-is-in-class as pointed out shyamendra – mane Aug 06 '14 at 12:02
0

you can try this

 (Foo.apply _).tupled
Uraniium
  • 109
  • 6