Scala与java线程错误:错误的符号引用

时间:2016-07-05 15:08:40

标签: multithreading scala scalac

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

0 个答案:

没有答案