-
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ν λ‘ νκ³ μΆμ μ§λ¬Έμ
λλ€.ν λ‘ νκ³ μΆμ μ§λ¬Έμ
λλ€.