Skip to content

Instantly share code, notes, and snippets.

@olegchir
Created October 5, 2019 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegchir/bf6a31fa80a64467d117783329f88c7b to your computer and use it in GitHub Desktop.
Save olegchir/bf6a31fa80a64467d117783329f88c7b to your computer and use it in GitHub Desktop.
//package com.example.helloworld;
//public final class HelloWorld {
// public static void main(String[] args) {
// System.out.println("Hello, 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment