2

TIL vanilla Java has the facilities to do (some form) of arbitrary compile time metaprogramming via annotation processors

Comments
  • 3
    yupp. Basically, you write code that will be run by the compiler to generate java code moments before the actual compilation.

    The problem is, that Java's MirrorAPI is a PITA to work with 😅 And long outdated (~java5) docs don't make it any easier.

    e.g. There are several ways to reference a type/class (4 or 5?) and they all have different properties and can be obtained through different builders/factories/other sources. And some of them one piece of data and the others have some other data and it's quite a pain to orchestrate them all in a single annotation processor :)
  • 1
    @netikras Oh boy, I just learned about it's existence and have to use it for a uni assignment so sounds like I'm in for a world of fun 🙃
  • 2
    @12bitfloat at keast you know now it won't be a breeze and can plan your time ahead. Also, you have a good hint that took me a while to dig up - the keyword 'Mirror API' :)
  • 1
    Btw another cool thing Java can do is javaagent :) not related to the annot. processor, but related to 'cool things java can do' ;)

    it's a security risk if mishandled, but also hell of a feature for an sre/middleware/perf team
  • 1
    @netikras Java agent I already knew about, and it's actually even cooler IMO :D

    Minecraft core modding for dayys
Add Comment