Skip to content

ITEM 35. ordinal 메서드 대신 인스턴스 필드를 사용하라 #62

@sypark9646

Description

@sypark9646

아래 코드를 enum 과 인스턴스 필드를 사용하여 중복을 제거 해 봅시다.

class Distance{

    private int east;
    private int west;
    private int north;
    private int south;


    public void setEast(int east){ this.east = east; }
    public void setWest(int west){ this.west = west; }
    public void setNorth(int north){ this.north = north; }
    public void setSouth(int south){ this.south = south; }


    public int getEast() { return east; }
    public int getWest() { return west; }
    public int getNorth() { return north; }
    public int getSouth() { return south; }
}

출처: https://effectiveprogramming.tistory.com/entry/enum-을-배열의-인덱스로-활용하는-방법

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions