Ich habe einen Beispielcode:Fehler bei SPARK REPL (Verweis auf A ist mehrdeutig) und funktioniert in Intellij und Scala REPL?
class A(str: String) {
println(s"InsideCase:::$str")
}
object A {
def apply(str: String) = {
println("foobar::")
new A(str)
}
}
object b extends App {
A("kool")
}
Dieser Code funktioniert in IntelliJ in Ordnung. Und gibt mir Ausgabe:
foobar::
InsideCAse:::kool
aber wenn ich versuche dies auf REPL zu tun:
scala> :paste
// Entering paste mode (ctrl-D to finish)
class A(str: String) {
println(s"InsideCAse:::$str")
}
object A {
def apply(str: String) = {
println("foobar::")
new A(str)
}
}
// Exiting paste mode, now interpreting.
defined class A
defined object A
scala> A("kool")
Es gibt mir die folgende Fehlermeldung:
<console>:27: error: reference to A is ambiguous;
it is imported twice in the same scope by
import $line31$read.A
and import INSTANCE.A
A("kool")
Was ich hier fehlt? Wenn Sie bitte ausführlich erklären können, wäre das hilfreich.
Es funktioniert gut für mich. –
Es funktioniert auf Scala REPL dann Warum funktioniert es nicht auf SPARK REPL? –