lombock

Jay·2023년 8월 27일

Spring

목록 보기
7/17
필요한 메소드/생성자등을 자동 생성해주는 라이브러리
Settings -> Annotation Processors -> Enable~~
shift 두번 -> plugins -> Lombock
package com.sparta.springpre;

import lombok.*;

@Setter
@Getter // 이 annotation을 통해서 getMethod를 자동으로 생성(build파일쪽에 -> 그리고빌드를해야지생성)
// @AllArgsConstructor // 모든 필드를 가지고있는 생성자 만들어줌 / 이경우에는 기본생성자를 만들어주지않는다
// @NoArgsConstructor // 기본생성자
@RequiredArgsConstructor // final이 달린 필드를 생성
public class Memo {
    private final String username;
    private String contents;

}

class Main{
    public static void main(String[] args){
        Memo memo = new Memo("야 시비냐고");
        memo.setContents("아 존나 방항적이네");
        System.out.println(memo.getContents());
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

// lombok을 사용하고 있는 파일에서 build를 하면 build파일 안에 자동 생성됨

package com.sparta.springpre;

public class Memo {
    private final String username;
    private String contents;

    public void setContents(final String contents) {
        this.contents = contents;
    }

    public String getUsername() {
        return this.username;
    }

    public String getContents() {
        return this.contents;
    }

    public Memo(final String username) {
        this.username = username;
    }
}

0개의 댓글