vendredi 26 juin 2020

NoSuchMethodException while accessing Kotlin Data class using reflection

I keep getting the following error while tryign to use reflection to access a kotlin data class java.lang.NoSuchMethodException: <init> [interface java.util.List, class java.lang.Boolean]

List<String> names = new ArrayList();
boolean isValid = false;
Class[] type = { List.class, Boolean.class };
Class dataClass = Class.forName("com.randome.model.Data");
Constructor DataConstructor = dataClass.getConstructor(type); // problem here 
Object[] dataObject = { names, isValid };
Object data = inAppContactDataConstructor.newInstance(dataObject);

// Data Class

@Parcelize
data class Data(
    val names: List<String>,
    val isValid: Boolean
): Parcelable




Aucun commentaire:

Enregistrer un commentaire