samedi 17 juin 2017

Java 'implements runnable' thread to execute reflection class

I am attempting to create an 'implements runnable' thread for a class of unknown name containing one parameterless constructor.

Current code:

Class<?> classEx = Class.forName("ArbitraryClassName.java").getClass();
Constructor<?> constructorEx = classEx.getConstructor();
Object objectEx = constructorEx.newInstance();

Thread threadEx = new Thread(objectEx);
threadEx.start();

However, I receive the error:

Cannot resolve constructor 'Thread(java.lang.reflect.Constructor<capture<?>>)'

How can a reflection be passed during thread instantiation?





Aucun commentaire:

Enregistrer un commentaire