I have this interface:
public interface Persistant<T extends BaseDaoEnabled<T, UUID>> extends Identifiable {
T getSelf();
default <P> P getInstance(DataKey<P> key) {
return key.getDefaultInstance();
}
and a class that implements it. My problem is that when I call obj.getInstance(DataKeys.X)
, X being a DataKey<X>
object, the return type of this method is Object
and not X
, the generic type is stripped. When I put the method inside my object class (not interface), it works just fine. See the screenshot below:
First method is from the interface, 2nd method is from the class. They both have the SAME signature
The interface has a type parameter (Persistant<T...>
) that I forgot to include on my Resident/obj
class. I was implementing it by just using implements Persistant
, implementing it using implements Persistant<Resident>
fixed my issue!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With