mercredi 10 janvier 2018

Java Reflection make final method non final

I know the way to make a Field non final via Reflection. But is there a way to make a method non final? Somehow the same approach does not work.

    // make all methods non final
    Clazz.javaClass.declaredMethods.forEach { method ->
        method.isAccessible = true
        val modifiersField = method.javaClass.getDeclaredField("modifiers")
        modifiersField.isAccessible = true
        modifiersField.setInt(method, modifiersField.modifiers and Modifier.FINAL.inv())
    }





Aucun commentaire:

Enregistrer un commentaire