// do non-generic subclasses still depend on type erasure import java.lang.reflect.*; class A {} class B {} // Defeating type erasure: // construct your own instantiations of generic, abstract classes abstract class Abst { T x; T[] R; abstract T getstatic(); abstract T[] makearray(int size); void printstatic() { System.out.println("here's your static: "+getstatic()); } void info() { try { Field xvar = Abst.class.getDeclaredField("x"); //Field xvar = this.getClass().getDeclaredField("x"); System.out.println("type of x is "+xvar.getType()); } catch (Exception e) {System.out.println(e);} } }//Abst class class concrete1 extends Abst { static String y="concrete"; String getstatic() { return y; } String[] makearray(int size) { return new String[size]; } public concrete1(String a) { x=a; R=makearray(100);} }//concrete1 class concrete2 extends Abst { static Double y=2.2; Double getstatic() { return y; } Double[] makearray(int size) { return new Double[size]; } public concrete2(Double a) { x=a; R=makearray(200);} @Override void info() { try { Field yvar = this.getClass().getDeclaredField("y"); System.out.println("type of y in concrete2 is "+yvar.getType()); Field xvar = this.getClass().getSuperclass().getDeclaredField("x"); System.out.println("type of x in from concrete2.super is "+xvar.getType()); //no such field exception } catch (Exception e) {System.out.println(e);} } }//concrete2 public class generics2 { public static void main(String[] av) { concrete1 c1 = new concrete1("abc"); concrete2 c2 = new concrete2(12.3); c1.info(); c2.info(); }//main }