I have an object where the type of a generic T is lost at some point through a giant chain of interfaces. I was wondering if it is possible to use a function to restore some type safety by checking types:
private T metaData; // type of T is lost public <R> R getMetaData(Class<R> className) { assert className.isInstance(metaData); return (R) metaData; }
However, this implementation generates the warning โUnverified cast:โ T โtoโ R. โIs there an implementation that avoids this warning or is it the only solution to suppress it?
source share