Skip to content

Instantly share code, notes, and snippets.

@bzdgn
Last active October 30, 2015 20:10
Show Gist options
  • Save bzdgn/ad8638596c28bbfedf75 to your computer and use it in GitHub Desktop.
Save bzdgn/ad8638596c28bbfedf75 to your computer and use it in GitHub Desktop.
Java Generic Instance Test
// Demonstraction on the wikipedia article sample code, actual source;
// https://en.wikipedia.org/wiki/Generics_in_Java#Problems_with_type_erasure
package com.levent.typeerasure;
import java.util.ArrayList;
public class GenericInstanceTest {
public static void main(String[] args) {
ArrayList<Integer> li = new ArrayList<Integer>();
ArrayList<Float> lf = new ArrayList<Float>();
if (li.getClass() == lf.getClass()) { // evaluates to true
System.out.println("Runtime instances are Equal");
System.out.println("...[Integer] ArrayList Runtime Class: " + li.getClass());
System.out.println("...[Float ] ArrayList Runtime Class: " + lf.getClass());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment