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

无人久伴 提交于 2020-05-10 21:07:47

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/58443039/is-there-a-way-to-create-custom-annotations-in-scala-and-write-a-custom-annotati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!