SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top