1

I'm new to scala and trying to play with it. I created new threads to run a test, when compiling the code with thread.join I get compilation error:

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.

without thread.join the code compiles and run

here is my code:

      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)
    }
  }

}

what am I doing wrong? I know the code is not clean, yet it's only a play with scala test

apolak
  • 141
  • 1
  • 14

0 Answers0