item 36 : 비트 필드 대신 EnumSet을 사용하라
1. 비트 필드 열거 상수
public class StyleWithBitField {
public static final int STYLE_BOLD = 1 << 0; // 1
public static final int STYLE_ITALIC = 1 << 1; // 2
public static final int STYLE_UNDERLINE = 1 << 2; // 4
public static final int STYLE_STRIKETHROUGH = 1 << 3; // 8
public void applyStyles(int styles) {
// styleWithBitField.applyStyles(STYLE_BOLD | STYLE_UNDERLINE);
}
}1) 비트 필드란?
text.applyStyles(STYLE_BOLD | STYLE_ITALIC);2) 비트 필드의 단점
예제 코드: for 문을 사용하여 모든 비트를 순회하는 방법
for 문을 사용하여 모든 비트를 순회하는 방법결과
장점과 단점
2. EnumSet
1) EnumSet의 장점과 예제 코드
EnumSet의 장점과 예제 코드요약
주의 사항
Last updated