在使用泛型程式碼中,常會遇到編譯器的警告。
- unchecked cast warning
- unchecked method invocation warnings
- unchecked parameterized vararg type warning
- unchecked conversion warning
// java.util.ArrayList source code
public void forEach(Consumer action) {
Objects.requireNonNull(action);
final int expectedModCount = modCount;
@SuppressWarnings("unchecked")
final E[] elementData = (E[]) this.elementData;
final int size = this.size;
//...
}
轉載請註明原文網址 https://cookieandcoketw.blogspot.com/2020/07/effective-java-27-unchecked-warning.html
沒有留言:
張貼留言