5 comments

  • pjmlp
    5 hours ago
    Note that Java now has its own API for this purpose.

    https://openjdk.org/jeps/484

    • atomicnumber3
      4 hours ago
      for those who might be clicking through thinking "since when??", the emphasis is on "now" - this was released in JDK 24.

      bytebuddy predates it by at least a decade.

      • pjmlp
        4 hours ago
        Hence the now on my comment. :)
    • zappb
      3 hours ago
      Ideally, tools like ByteBuddy will adopt that API as it's for low level concerns.
    • brabel
      4 hours ago
      How does that compare in terms of usability and completeness?
      • aardvark179
        1 hour ago
        It is complete, and I’ve found it extremely usable when writing code to trawl over a large number of class files. Looks like it should be good for code generation as well but I haven’t used that yet.
      • pjmlp
        4 hours ago
        I have not yet used it, only raising awareness.

        This came to be, because Oracle noticed everyone, including themselves, were depending on ASM, so the JEP was born.

        • cogman10
          4 hours ago
          Yup, the ASM dependency is one that would constantly cause us headaches. A load of frameworks have a path to ASM for one reason or another and it requires an update every time you move up JVM runtimes.

          It's usually not painful to update (just bump the version) but it's an annoyance.

          In fact, Byte buddy has a dep on ASM.

      • cogman10
        4 hours ago
        It's complete but low level compared to Byte Buddy. A better comparison is the to ASM (which is what it was meant to replace).

        https://asm.ow2.io/

  • cogman10
    4 hours ago
    If you are into code generation, another project of interest is Java Poet

    https://github.com/square/javapoet

    I've used it to do a mass refactoring of an annotation-based library. Worked pretty great.

  • selimco
    3 hours ago
    It seems like micronaut has been able to avoid runtime bytecode generation by doing everything at compile-time. I wonder if there’s things that you can’t do the micronaut way.
  • morkalork
    5 hours ago
    Reminds me of a side project I did when first starting CS! The Java byte code specification is absolutely approachable and if you've never looked at it before I recommend it (although this project says you can still use it without that knowledge)
  • ActorNightly
    3 hours ago
    The better question is why use Java for anything these days. If you really need to run something with JVM, use Kotlin.
    • AdieuToLogic
      31 minutes ago
      > The better question is why use Java for anything these days.

      Java (the language) is pretty much "C for the JVM." By that, I mean frameworks/libraries intended for maximum potential use in languages running on the JVM (such as Kotlin, Scala, and of course Java) all support Java (the language) interoperability. Many written in alternate languages targeting the JVM, such as Akka[0], typically have some degree of Java (the language) support as well.

      While I prefer to program in one of the alternate programming languages targeting the JVM, I understand why many OSS projects are implemented in Java (the language) for the reasons outlined above.

      0 - https://github.com/akka/akka

    • ackfoobar
      3 hours ago
      As a Kotlin enjoyer, I find these comments counterproductive. Maybe they like the lack of extension functions?
      • kachapopopow
        3 hours ago
        Kotlin is fatter, compiler is slower, code completion is slow as hell on large projects, but other than building small applications - there's really no reason to not use kotlin except for the fact that you need to actually learn the language or else you're going to end up with very very slow codebase where opening a file and waiting for syntax highlighting takes 2-3 seconds and typing autocomplete is just painfully slow.
        • switchbak
          1 hour ago
          "fatter, compiler is slower, code completion is slow as hell" - if that's all you want out of your programming language, then Java is probably a good choice for you.

          For others that value the things that Kotlin brings over Java (even modern Java), and for the ways in which it delivers a simpler experience than Scala - I think it's a pragmatic and sensible decision.

      • vips7L
        1 hour ago
        I do like the lack of extension functions. I find them confusing, especially when you can use them on things that are null.