Code generation on the Java VM 2019-12-05

99d4c0ed3c8027ea1c37b53d6441d042?s=47 sullis
December 05, 2019

Code generation on the Java VM 2019-12-05

December 5, 2019




December 05, 2019


  1. 5.

    class names parameter names method names exception names Consistency error

    handling logging JSON serialization network I/O
  2. 21.

    “Unlike Spring which relies exclusively on runtime reflection and proxies,

    Micronaut uses compile time data to implement dependency injection” micronaut
  3. 22.

    “This goal is achieved through the use of Java’s annotation

    processors" micronaut
  4. 25.
  5. 27.

    “Mockito switched from CGLIB to the great library ByteBuddy to

    make mocks” mockito 2.x
  6. 39.
  7. 41.

    package com.example.helloworld; public final class HelloWorld { public static void

    main(String[] args) { System.out.println("Hello, JavaPoet!"); } } JavaPoet
  8. 42.

    import com.squareup.javapoet.*; MethodSpec main = MethodSpec.methodBuilder("main") .addModifiers(Modifier.PUBLIC, Modifier.STATIC) .returns(void.class) .addParameter(String[].class,

    "args") .addStatement("$T.out.println($S)", System.class, "Hello, JavaPoet!") .build(); TypeSpec helloWorld = TypeSpec.classBuilder("HelloWorld") .addModifiers(Modifier.PUBLIC, Modifier.FINAL) .addMethod(main) .build(); JavaFile javaFile = JavaFile.builder("com.example.helloworld", helloWorld) .build(); javaFile.writeTo(System.out); JavaPoet method builder class builder file builder
  9. 44.

    AWS SDK for Java v2 “To provide SDK support for

    the many services that AWS owns, the AWS SDKs make extensive use of code generation”
  10. 47.
  11. 48.

    “Dagger 2 is the first to implement the full stack

    with generated code” Dagger 2.x “Dependency injection frameworks have existed for years with a whole variety of APIs for configuring and injecting”
  12. 69.

    Final thoughts code generation is a powerful technique use a

    code generator to generate client libraries contribute to open source projects
  13. 71.