samedi 15 août 2015

Java reflection isAccesible method

I'm learning reflection. When I execute the following code:

package main;

import java.lang.reflect.Field;

public class Main {
    public static void main(String[] args) throws NoSuchFieldException, SecurityException {

        Base firstBase = new Base();
        Field firstBaseField = firstBase.getClass().getDeclaredField("protectedBuffer");
        System.out.println(firstBaseField.isAccessible());

    }
}

This is Base class:

package main;

public class Base {

    private StringBuffer buffer;
    protected StringBuffer protectedBuffer;
    public StringBuffer buffer2;

}

the result is false. But shoudn't it be true, because I can access protectedBuffer in this way: firstBase.protectedBuffer?





Aucun commentaire:

Enregistrer un commentaire