Types in a package object

Maybe I'm missing something obvious, but:

package.scala

package heptic package object proj { case class Jesus(axes: Int) def foo: Jesus = Jesus(44) } 

Gives a compilation error:

 found : heptic.proj.Jesus required: heptic.proj.package.Jesus def foo: Jesus = Jesus(44) ^ 

which doesn't seem to make much sense (especially when the type output is from the compiler (last, 2.10.1))

+4
source share
3 answers

sbt clean for such errors.

Another Jesus class was compiled and not removed. I think you moved Jesus from package to package object and got both of them.

+3
source

I want to make this work correctly, I believe that you need to put this code in a file called package.scala in the folder structure '/ heptic / proj' (under your source folder). The scala file must be called package.scala , and it must be under the appropriate folder structure of the package so that it really behaves like a package object.

0
source

declare a case class in a package, but not in a package object:

 package heptic package object proj { def foo: Jesus = Jesus(44) } package proj { case class Jesus(axes: Int) } 
0
source

Source: https://habr.com/ru/post/1479780/


All Articles