Reputation: 460
I'm developing a Scala package using an sbt project scheme through IntelliJ. I wanted to use the classes in this package in the Scala REPL, so I followed the instructions in this post. Namely,
This all works fine until I try to create an instance of one of my package's classes and I get the error MyClass does not have a constructor
. However, if I just paste the class definitions into the Scala REPL, I can create instances with no errors. What am I doing wrong here?
As a reproducible example, I created a package mytest
with two files TraitOne.scala
and ClassOne.scala
. The first file looks like
package mytest
trait TraitOne {
val a: Double
def aMinus(x: Double): Double = a - x
}
The second file looks like
package mytest
class ClassOne(val a: Double) extends TraitOne {
def aPlus(x: Double): Double = a + x
}
If I follow steps 1 - 4 as listed above and write val temp = new ClassOne(1.0)
, I get the error ClassOne does not have a constructor
. But if I paste
trait TraitOne {
val a: Double
def aMinus(x: Double): Double = a - x
}
class ClassOne(val a: Double) extends TraitOne {
def aPlus(x: Double): Double = a + x
}
into the REPL, val temp = new ClassOne(1.0)
works fine.
Upvotes: 0
Views: 61
Reputation: 11
Run scala -cp MyProject/src/main/scala/mypackage/target/scala-2.12/classes
Don't include the package in classpath
Upvotes: 0