Skip to content

Instantly share code, notes, and snippets.

@seungdols
Forked from choiseungho/GenericsErasure.java
Created November 26, 2015 12:30
Show Gist options
  • Save seungdols/b3c203ad0d3a086da945 to your computer and use it in GitHub Desktop.
Save seungdols/b3c203ad0d3a086da945 to your computer and use it in GitHub Desktop.
java의 generics Erasure 한계를 보여주는 코드
package com.tistory.seungdols;
import java.util.ArrayList;
import java.util.List;
/**
* @PROJECT bytecodeTest
* @PACKAGE com.tistory.seungdols
* @WRITTER Administrator
* @DATE 2015-11-05
* @HISTORY
* @DISCRIPT
*/
public class GenericsErasure {
public static void main (String[] args) {
List<Apple> appleList = new ArrayList<> ();
List<Orange> orangeList = new ArrayList<> ();
Apple apple = new Apple ();
add (apple);
add (orangeList);
}
public static <E>void add (E fruit)
{
if(fruit instanceof Apple)
{
System.out.println ("Apple");
}
else if(fruit instanceof List<?>)
{
System.out.println ("Apple List");
}
}
}
class Apple
{
}
class Orange
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment