mercredi 10 mars 2021

Generic type, cast to method,field

i have this class

class GameLoaderClass<V> {

V classValue = null;

Class<?> aClass;

ClassType classType;

public GameLoaderClass(ClassType classType, Class<?> aClass) {
    this.classType = classType;
    this.aClass = aClass;
}

public V getClassType(String name) {
    if (this.classType == ClassType.FIELD) {
        return this.classValue = aClass.getDeclaredField(name);
    } else
        return this.classValue = aClass.getMethod(name);

}

But i get this following error..

Required type: C Provided: Method

any way to fix it?, thanks





Aucun commentaire:

Enregistrer un commentaire