1. 생성후 값을 바꿀수 없다. 아래와 같이 final로 정의 되어져 있다
/** The value is used for character storage. */
private final char value[];
2. Exception의 새로운 사용 방법을 알게 되었다.
public String(char value[], int offset, int count) {
if (offset < 0) {
throw new StringIndexOutOfBoundsException(offset);
}
...
}
offset이 범위 밖일때는 StringIndexOutOfBoundsException을 생성하여 던진다.
StringIndexOutOfBoundsException는 RuntimeException을 상속 받았다.
!위와 같이 RuntimeException을 상속하여 User Defined Exception을 생성하여 사용한다면 가독성과 유지보수에 도움이 될 듯하다.
3. equals()와 hashCode()를 overriding했다.
- equals()는 각 index의 char값을 비교.
- hashCode()는 아래 식을 이용하여 생성한다.
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
댓글 없음:
댓글 쓰기