Fügen Sie Folgendes zu den "Abhängigkeiten" von "build.gradle" hinzu
build.gradle
compileOnly 'org.projectlombok:lombok:1.18.8'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
delombok
ausführen
--Wenn Sie über die Befehlszeile prüfen,java -jar <lombok.Glaspfad> delombok -p <Kommentierter Klassenpfad>
@Getter
/ @Setter
Grantor
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
public class Human {
private int age;
private String name;
private List<String> hobby;
}
Generierte Klasse
import java.util.List;
public class Human {
private int age;
private String name;
private List<String> hobby;
@java.lang.SuppressWarnings("all")
public int getAge() {
return this.age;
}
@java.lang.SuppressWarnings("all")
public String getName() {
return this.name;
}
@java.lang.SuppressWarnings("all")
public List<String> getHobby() {
return this.hobby;
}
@java.lang.SuppressWarnings("all")
public void setAge(final int age) {
this.age = age;
}
@java.lang.SuppressWarnings("all")
public void setName(final String name) {
this.name = name;
}
@java.lang.SuppressWarnings("all")
public void setHobby(final List<String> hobby) {
this.hobby = hobby;
}
}
@ToString
Grantor
import lombok.ToString;
import java.util.List;
@ToString
public class Human {
private int age;
private String name;
private List<String> hobby;
}
Generierte Klasse
import java.util.List;
public class Human {
private int age;
private String name;
private List<String> hobby;
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "Human(age=" + this.age + ", name=" + this.name + ", hobby=" + this.hobby + ")";
}
}
@NoArgsConstructor
/ @RequiredArgsConstructor
/ @AllArgsConstructor
-- @ NoArgsConstructor
: Generiert automatisch einen Konstruktor ohne Argumente
-- @ RequiredArgsConstructor
: Generiert automatisch einen Konstruktor, der ein Feld mit final als Argument verwendet
-- @ AllArgsConstructor
: Generiert automatisch einen Konstruktor mit allen Feldern als Argumenten
Grantor(@AllArgsConstructor)
import lombok.AllArgsConstructor;
import java.util.List;
@AllArgsConstructor
public class Human {
private int age;
private final String name;
private List<String> hobby;
}
Generierte Klasse
import java.util.List;
public class Human {
private int age;
private final String name;
private List<String> hobby;
@java.lang.SuppressWarnings("all")
public Human(final int age, final String name, final List<String> hobby) {
this.age = age;
this.name = name;
this.hobby = hobby;
}
}
@Data
@Getter
/ @Setter
@ToString
@EqualsAndHashCode
@RequiredArgsConstructor
@Value
@Builder
Grantor
import lombok.Builder;
import java.util.List;
@Builder
public class Human {
private int age;
private final String name;
private List<String> hobby;
}
Seite zu verwenden
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<String> hobby = Arrays.asList("Futsal", "Diät", "lesen");
Human human = new Human.HumanBuilder().age(20).name("Nennen Sie Taro").hobby(hobby).build();
System.out.println(human);
}
}
Generierte Klasse
import java.util.List;
public class Human {
private int age;
private final String name;
private List<String> hobby;
@java.lang.SuppressWarnings("all")
Human(final int age, final String name, final List<String> hobby) {
this.age = age;
this.name = name;
this.hobby = hobby;
}
@java.lang.SuppressWarnings("all")
public static class HumanBuilder {
@java.lang.SuppressWarnings("all")
private int age;
@java.lang.SuppressWarnings("all")
private String name;
@java.lang.SuppressWarnings("all")
private List<String> hobby;
@java.lang.SuppressWarnings("all")
HumanBuilder() {
}
@java.lang.SuppressWarnings("all")
public HumanBuilder age(final int age) {
this.age = age;
return this;
}
@java.lang.SuppressWarnings("all")
public HumanBuilder name(final String name) {
this.name = name;
return this;
}
@java.lang.SuppressWarnings("all")
public HumanBuilder hobby(final List<String> hobby) {
this.hobby = hobby;
return this;
}
@java.lang.SuppressWarnings("all")
public Human build() {
return new Human(age, name, hobby);
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "Human.HumanBuilder(age=" + this.age + ", name=" + this.name + ", hobby=" + this.hobby + ")";
}
}
@java.lang.SuppressWarnings("all")
public static HumanBuilder builder() {
return new HumanBuilder();
}
}
@NonNull
@EqualsAndHashCode
equals ()
, hashCode ()
@Log
@Code, der beim Hinzufügen von Slf4j generiert wird
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExample.class);
var
/ val
Recommended Posts