Annotate new keyword

Hello to all,

Is it possible to annotate new keyword in Scala?

In Java I imported my own annotation in java/lang and I am able to
annotate new operation just like that (and it work):
String str = new @Cache String(“Hello World”)

Is it possible with Scala too? I tried the following but it did not work:
val str: String = new @Cache String(“Hello World”)

Does this work?

new (String @Cache)("Hello World")

But also, please ask usage questions like this over at https://users.scala-lang.org.

(Or, if this is in the context of some Scala contribution you are working on and that’s why you asked here, then please make that context clear.)

3 Likes

Hello and thanks for the reply.

Well I am working to implement a garbage collection and I want to move certain objects in different generations. So I want to annotate new operation as I did in Java.

This could be an extension of Scala language to provide hints to JVM to allocate objects in certain generations.

1 Like