Created
October 5, 2019 19:48
-
-
Save olegchir/bf6a31fa80a64467d117783329f88c7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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