On Mon, Jun 27, 2016 at 1:09 PM, Nicolas Passerini <[email protected]> wrote:


On Mon, Jun 27, 2016 at 1:44 PM, Denis Kudriashov <[email protected]> wrote:

2016-06-27 13:28 GMT+02:00 Nicolas Passerini <[email protected]>:
That is not quite true, annotations are (kind of) objects but you can not put behavior in them, just define attributes and optionally default values for those attributes.

Ah, you are right. I remember many restrictions was applied to them which always forced me to hate Java :)

Yep.

Well, there's a reason why they're restricted. Note, that the restriction is on language level, not at runtime level. A annotation class with arbitrary code would pass JVM verification (or at least I can't see a rule that would reject such a class).

When I implemented annotation support I was initially thinking the same - let's create an instance of CoolAnnotationClass when the code is accepted and then one can add arbitrary code to his CoolAnnotationClass. I quickly realized this is a (very) bad idea. Or, to be precise, it is a bad idea given the
environment. So I'd be very careful..

Jan

P.S.: As for "which always forced me to hate Java": I found myself a very enlightening to think carefully about why somebody else do things differently before I start to hate her/him. Besides, there's whole lot of things that Java guys got right...



Reply via email to