Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to create custom annotations in Scala and write a custom annotation processor to verify the annotations?

I have been learning about annotations and what an annotation processor is. I was looking at Java examples and there seems to be a proper way to do it. However, in Scala, I do not get a proper website/documentation to create custom annotations and annotation processor.

If it's not possible in Scala, is there a way to use Java custom annotation processor in Scala classes?

Can someone point me in the right direction?

like image 350
arvind_ganesan Avatar asked Oct 18 '19 02:10

arvind_ganesan


2 Answers

In Scala there are macro annotations

https://docs.scala-lang.org/overviews/macros/annotations.html

I guess this is similar to compile-time processing annotations in Java.

like image 77
Dmytro Mitin Avatar answered Oct 21 '22 15:10

Dmytro Mitin


In Scala there is an option to use compile-time annotations in black-box (type-safe) macros without need to add a compiler extensions or flags.

Here is an example of defining and usage of such annotations for derivation of codecs.

like image 43
Andriy Plokhotnyuk Avatar answered Oct 21 '22 16:10

Andriy Plokhotnyuk