Why scala people don't like annotation?

后端 未结 4 1219
傲寒
傲寒 2021-02-04 01:01

Attribute in .NET is a very popular feature. And Java added Annotation after 1.5 Annotations are used everywhere, see Java EE and Spring. But few scala library use annotation. l

4条回答
  •  情深已故
    2021-02-04 01:16

    You've pretty much answered your own question when you said that they're used for compiler magic. For the other uses it's usually some kind of runtime magic, where the two main tools are reflection and byte code transformation.

    For the JSON case, the choices for the conversion would be the following: 1. A function or class that parses your JValue and builds your class T. 2. Reflection over the target classes to determine their layout and what is optional, then some "dynamic" code which runs over that parsed data to create and then eventually cast to the appropriate type.

提交回复
热议问题