A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Adventures in Scala 1.0

Mac OSX:

brew install sbt@1

Try the "Hello, World" example from scala-lang.org:

object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
  }
}

Run it:

Go [15:46:  learning-scala$] sbt run
[warn] No sbt.version set in project/build.properties, base directory:~alt/learning-scala
[info] Set current project to learning-scala (in build file:~/alt/learning-scala/)
[info] Compiling 1 Scala source to ~/alt/learning-scala/target/scala-2.12/classes ...
[info] Non-compiled module 'compiler-bridge_2.12' for Scala 2.12.4. Compiling...
[info]   Compilation completed in 11.024s.
[info] Done compiling.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.protobuf.UnsafeUtil (file:~/.sbt/boot/scala-2.12.4/org.scala-sbt/sbt/1.1.0/protobuf-java-3.3.1.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of com.google.protobuf.UnsafeUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[info] Packaging ~/alt/learning-scala/target/scala-2.12/learning-scala_2.12-0.1.0-SNAPSHOT.jar ...
[info] Done packaging.
[info] Running HelloWorld 
Hello, world!
[success] Total time: 16 s, completed 9 Feb 2018, 15:47:03


Well, it worked. But that's a helluva lot of warnings for very little code!

A colleague informs me how to set up another Hello World that's known to work:

sbt new https://github.com/scala/scala-seed.g8
(enter name: hello)
cd hello
sbt run

...but I still get the warnings, although the code does output "hello" as expected.

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.protobuf.UnsafeUtil (file:~/.sbt/boot/scala-2.12.4/org.scala-sbt/sbt/1.1.0/protobuf-java-3.3.1.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of com.google.protobuf.UnsafeUtil

It seems I've just joined Scala at a time when 1.0 has recently been released, and lots of existing code does not exactly make the compiler happy yet.

Note: The warning was not displayed the second time I ran the program. Somehow it remembers.

To do:
  • Find out how to avoid the warning.
  • Find out how to repeat the warning!