You can find the compiled methods with javap -c MyClass :
Compiled from "Test.java" class MyClass implements Id<java.lang.Long> { MyClass(); Code: 0: aload_0 1: invokespecial
As you can see, there are 2 methods for getId , one return type is Long as implementation , and the other return type is Object (it calls the Long getId method).
method It is intended for processing when the general type and Long getId bridge are not specified. Example:
Id<Long> id = new Id<Long>() { @Override public Long getId() { return null; } }; Long id1 = id.getId();
as the code snippet above, we can implement the anonymous class Id with type Long . but we can also implement the anonymous class Id without specifying a generic type in the variable:
Id id = new Id<Long>() { @Override public Long getId() { return null; } }; Object id1 = id.getId();
therefore, at the moment, the compiler cannot deduce a common type for the Id variable when id.getId() returns an Object type, which means that it calls this method public java.lang.Object getId(); and bridge to public java.lang.Long getId(); .
source share