Scala 2.12 (Java 8) annotation on types?


#1

Is it possible to use annotations on types with Scala 2.12?

I mean in Java 8 this become possible:

 List<@NonNull String> list = new ArrayList<@NonNull String>();

Is it possible with Scala too? I tried the following, but it did not work:

 val ls: Seq[@NonNull String] = List.empty[@NonNull String]

Error:(8, 15) identifier expected but ‘@’ found.

Is the syntax different?

I was searching in the release notes of 2.12, but could not find mentioning it. Are there plans to support this (and probably also module annotations in Java 9)?


#2

The syntax is different: it’s String @NotNull instead of @NotNull String. You didn’t find it in the release notes of 2.12 because it’s been supported in Scala for a long time (at least as far as my memory goes, i.e., 2.9.0).


#3

I think much longer than that – cps used it.