Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. //package com.example.helloworld;
  2. //public final class HelloWorld {
  3. // public static void main(String[] args) {
  4. // System.out.println("Hello, JavaPoet!");
  5. // }
  6. //}
  7.  
  8. MethodSpec main = MethodSpec.methodBuilder("main")
  9. .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
  10. .returns(void.class)
  11. .addParameter(String[].class, "args")
  12. .addStatement("$T.out.println($S)", System.class, "Hello, JavaPoet!")
  13. .build();
  14.  
  15. TypeSpec helloWorld = TypeSpec.classBuilder("HelloWorld")
  16. .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
  17. .addMethod(main)
  18. .build();
  19.  
  20. JavaFile javaFile = JavaFile.builder("com.example.helloworld", helloWorld)
  21. .build();
  22.  
  23. javaFile.writeTo(System.out);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement