Project Lombok makes java a spicier language by adding ‘handlers’ that know >how to build and compile simple, boilerplate-free, not-quite-java code.
@NonNull
java
public class NonNullExample extends Something { private String name; public NonNullExample(@NonNull Person person) { super("Hello"); this.name = person.getName(); } }
翻譯成java代碼 ==>
public class NonNullExample extends Something { private String name; public NonNullExample(@NonNull Person person) { super("Hello"); if (person == null) { throw new NullPointerException("person"); } this.name = person.getName(); } }
@Cleanup
ui
public class CleanupExample { public static void main(String\[\] args) throws IOException { @Cleanup InputStream in = new FileInputStream(args\[0\]); @Cleanup OutputStream out = new FileOutputStream(args\[1\]); byte\[\] b = new byte\[10000\]; while (true) { int r = in.read(b); if (r == -1) break; out.write(b, 0, r); } } }
翻譯成java代碼 ==>
public class CleanupExample { public static void main(String\[\] args) throws IOException { InputStream in = new FileInputStream(args\[0\]); try { OutputStream out = new FileOutputStream(args\[1\]); try { byte\[\] b = new byte\[10000\]; while (true) { int r = in.read(b); if (r == -1) break; out.write(b, 0, r); } } finally { if (out != null) { out.close(); } } } finally { if (in != null) { in.close(); } } } }
@Data
this
至關於翻譯
@ToString @EqualsAndHashCode @Getter(全部字段) @Setter (全部非final字段) @RequiredArgsConstructor