我在tutorialspoint上找到了這段代碼。代碼看起來非常直截了當。它從課堂角度調用移動方法。該方法在STDOUT上打印新的x/y座標。但是,它不,我不明白爲什麼。我在cygwin上的scala和cloudera VM上的spark-shell上都運行了代碼。相同的結果:-)scala類內的println不會在STDOUT上顯示輸出
感謝如果有人能指出(沒有雙關語意)我做錯了什麼。
class_plus.scala
:
import java.io._
class Point(val xc: Int, val yc: Int) {
var x: Int = xc
var y: Int = yc
def move(dx: Int, dy: Int) {
x = x + dx
y = y + dy
println ("Point x location : " + x);
println ("Point y location : " + y);
}
}
object Test {
def main(args: Array[String]) {
val pt = new Point(10, 20);
// Move to a new location
pt.move(10, 10);
}
}
然後我運行:
[email protected] ~
$ scala class_plus.scala
[email protected] ~
$
你在調用Test對象嗎? – hasumedic
沒有。我怎麼做?道歉爲虛假。 – Mamun
史蒂夫回答說的是我暗示你錯過了;)對不起,我沒有時間寫完整的答案。很高興現在正在工作。 – hasumedic