mardi 24 octobre 2017

Passing template parameters to Class#newInstance()

I have the following interface:

interface Processor<T> {
    void process( T request );
}

I then call the following:

Processor<String> p = Processor.class.newInstance();

Eclipse complains, as a warning against Processor.class.newInstance():

"Type safety: The expression of type Processor needs unchecked conversion to conform to Processor< String>"

How do I specify the template parameters to this expression? Something like:

Processor<String> p = Processor.class.newInstance<String>();





Aucun commentaire:

Enregistrer un commentaire