Ich lerne Scala, und ich habe versucht, von 2 Scripts in verschiedenen Klassen zu importieren, aber ich bekomme einen Fehler, und ich weiß nicht warum.Scala Error Import
Diese Klasse in Summer.scala, wo ich versuche, das Singleton-Objekt aus der Klasse ChecksumAccumulator zu importieren.
import ChecksumAccumulator.calculate
object Summer{
def main(args: Array[String]): Unit= {
for (arg <- args)
println(arg + " : " + calculate(arg))
}
}
Klasse ChecksumAccumulator, mit dem Singleton-Objekt ChecksumAccumulator.
object ChecksumAccumulator {
/*
When a singleton object shares the same name
with a class, it is called that class's companion object.
*/
private val cache = mutable.Map.empty[String, Int]
def calculate(s: String): Int =
if (cache.contains(s))
cache(s)
else {
val acc = new ChecksumAccumulator
//The object with the same name of the class can acces to the private members.
//println(acc.sum)
for (c <- s)
acc.add(c.toByte)
val cs = acc.checksum()
cache += (s -> cs)
cs
}
def showMap() : Unit = {
for(base:String <- cache.keys)
println(cache(base))
}
//def showMap(): String = { var cadena = cache("Every value is an object.") + " "+ cache("Every value is an object. per second time!!"); cadena }
}
Dieses Skript diesen Fehler werfen
scala Summer.scala
Summer.scala:8: error: not found: object ChecksumAccumulator import ChecksumAccumulator.calculate^Summer.scala:14: error: not found: value calculate println(arg + " : " + calculate(arg))^two errors found
Siehe http://stackoverflow.com/questions/1529434/how-to-split -a-scala-script-in-mehrere-Dateien. –