Java: properly checked class instantiation using reflection
I'm trying to use one of the simplest forms of reflection to create an instance of class: package some.common.prefix; public interface My { void configure(...); void process(...); } public class MyExample implements My { ... // proper implementation } String myClassName = "MyExample"; // read from an external file in reality Class<? extends My> myClass = (Class<? extends My>) Class.forName("some.common.prefix." + myClassName); My my = myClass.newInstance(); Typecasting unknown Class object we've got from Class.forName yields a warning: Type safety: Unchecked cast from Class<capture#1-of ?> to