Skip to main content

Posts

Showing posts from October, 2011

Java Problem: Generic Inheritance and Calling GetMethod().getReturnType()

In my current project, I have classes which are modeled like the following. At some point, a method like getReturnTypeForGetId() is called on classes A and B . Calling the method with A returns Integer as expected, but B returns Serializable . What am I missing here? Am I getting bitten by some heinous erasure thing, or am I just missing out on some sort of generic context-clobbering? EDIT: Adding an over-ridden getId() method to B fixes the problem, but I would still like to understand what I am running into. I've also asked this question on stackoverflow. import java.io.Serializable ; public class WeirdTester { static interface Identifiable & lt ; T extends Serializable > { T getId (); void setId ( final T id ); } static abstract class BaseEntity & lt ; T extends Serializable > implements Identifiable & lt ; T > { private T id ; public T getId () { return id ; }