-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
👨🏻💻 question토론하고 싶은 질문입니다.토론하고 싶은 질문입니다.
Description
소정(@iamsojung) 님이 질문해주셨던 힙 오염의 의미 참고 문서 첨부합니다!
https://en.wikipedia.org/wiki/Heap_pollution
In the Java programming language, heap pollution is a situation that arises when a variable of a parameterized type refers to an object that is not of that parameterized type.[1] This situation is normally detected during compilation and indicated with an unchecked warning.[1] Later, during runtime heap pollution will often cause a ClassCastException.[2]
런타임에 힙에 생성되는 인스턴스 타입이 컴파일타임의 타입과 다를 수 있는 상황에 Unchecked Warning 과 ClassCastException 이 발생할 가능성이 있다면 힙 오염이라고 표현한다고 합니다.
/**
* https://en.wikipedia.org/wiki/Heap_pollution
*/
public class HeapPollutionDemo
{
public static void main(String[] args)
{
Set s = new TreeSet<Integer>();
Set<String> ss = s; // unchecked warning
s.add(new Integer(42)); // another unchecked warning
Iterator<String> iter = ss.iterator();
while (iter.hasNext())
{
String str = iter.next(); // ClassCastException thrown
System.out.println(str);
}
}
}youngreal and iamsojung
Metadata
Metadata
Assignees
Labels
👨🏻💻 question토론하고 싶은 질문입니다.토론하고 싶은 질문입니다.