Last active
October 30, 2015 20:10
-
-
Save bzdgn/ad8638596c28bbfedf75 to your computer and use it in GitHub Desktop.
Java Generic Instance Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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