1

我是 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 测试的一个游戏

4

0 回答 0