lundi 7 juin 2021

How do I use reflection to invoke methods in Java 16?

Originally my code was normal reflection code, where you get a declared method, set it to be accessible, and then invoke it, but past Java 8 this does not seem to work. With a bit of googling, I found this article: https://blog.gotofinal.com/java/breakingjava/2017/11/08/reflections-in-java-9.html The article made sense, and I added the changes, but this line: Field methodModifiers = Method.class.getDeclaredField("modifiers"); throws a FieldNotFoundException. I decompiled the Java method class, and the field was there, exactly as it should be, but with an @Stable annotation. Normally FieldNotFoundExceptions are thrown when it is a private or protected field, and you use the getField method, but I'm really not sure why it is throwing the exception right now, as it uses getDeclaredField.





Aucun commentaire:

Enregistrer un commentaire