Is static metaprogramming possible in Java?

前端 未结 11 1174
無奈伤痛
無奈伤痛 2020-12-14 00:56

I am a fan of static metaprogramming in C++. I know Java now has generics. Does this mean that static metaprogramming (i.e., compile-time program execution) is possible in

11条回答
  •  一个人的身影
    2020-12-14 01:11

    No, this is not possible. Generics are not as powerful as templates. For instance, a template argument can be a user-defined type, a primitive type, or a value; but a generic template argument can only be Object or a subtype thereof.

    Edit: This is an old answer; since 2011 we have Java 7, which has Annotations that can be used for such trickery.

提交回复
热议问题