tonykang22 / study

0 stars 0 forks source link

[이펙티브 자바] 아이템 27. 비검사 경고를 제거하라 #149

Open callmeaxxe opened 1 year ago

callmeaxxe commented 1 year ago

아이템 27. 비검사 경고를 제거하라.

핵심 정리

Set names = new HashSet(); // 로타입. 비검사 경고가 발생한다
    public <T> T[] toArray(T[] a) {
        if (a.length < size) {
            // 이 애노테이션을 왜 여기서 선언했는지..
            @SuppressWarnings("unchecked")
            T[] result = (T[]) Arrays.copyOf(elements, size, a.getClass());
            return result;
        }
        System.arraycopy(elements, 0, a, 0, size);
        if (a.length > size)
            a[size] = null;
        return a;
    }
callmeaxxe commented 1 year ago

완벽 공략 41. 애너테이션

자바 애너테이션을 정의하는 방법

@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, MODULE})
@Retention(RetentionPolicy.SOURCE)
public @interface SuppressWarnings {
    String[] value();
}