vendredi 17 septembre 2021

Java reflection setAccessible field of String class

I have the following java code

public static void main(String[] args) {
    Class<?> clazz = "string".getClass();
    for (Field field : clazz.getDeclaredFields()) {
        field.setAccessible(true);
    }
}

But receive this warnings when I try to set field accessible:

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by xxx to field java.lang.String.value WARNING: Please consider reporting this to the maintainers of xxx WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release

How can I avoid this warning and fix this piece of code?





Aucun commentaire:

Enregistrer un commentaire