The id in BaseEntity is private and "Serializable or Extends Serializable".
Class B (which extends BaseEntity) knows nothing about this field. If he defined his own identifier and did not override getId () / setId (...), these two methods would continue to use BaseEntity.id
If you add this method to BaseEntity:
public void setId2(final Serializable id) { this.id = (T) id; }
it allows you to set BaseEntity.id to any Serializable.
In the next test, you can set the id field, for example. the Float value and all compiled and immutable getId () conveniently return the Float value.
B b = new B(); b.setId2(2.1F); System.out.println( b.getId() );
Therefore, if you do what you are doing and ask: โWhat is the return type of the B.getId () method,โ then if you did not override the getId () method in class B (which would force it to use the type of the Integer function and return Integer Note that BaseEntity.id will not even be visible to B then!) the reflection response is not integer, but general Serializable. Because any Serializable can really exit the getId () method.
source share