私はscalaが初めてで、それで遊ぼうとしています。テストを実行するために新しいスレッドを作成しました。コードを thread.join でコンパイルすると、コンパイル エラーが発生します。
Error:scalac: bad symbolic reference. A signature in package.class refers to type compileTimeOnly
in package scala.annotation which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling package.class.
thread.join なしでコードをコンパイルして実行する
ここに私のコードがあります:
class Test{
var counter = 0
@Test def testWithThreads(): Unit = {
var i = 0
while(i < 5) {
val thread = new Thread(new TestThread)
thread.start
thread.join
i+=1
}
}
class TestThread extends Runnable {
override def run(): Unit = {
println(counter+=5)
}
}
}
私は何を間違っていますか?コードがきれいではないことはわかっていますが、それはscalaテストでの遊びにすぎません