Where Java member variables go?

Accidentally knocked code, even by the compiler, which at low jdk version is definitely not allowed, the following code, the main function is normal operation, str keep gone?

 

Positive Solutions: First Filed array, can be treated with Java reflection knowledge

package cn.seaboot.common.db;

public class Test {
    interface A{
        void pr();
    }

    public static A createA(String str){
        return new A() {
            @Override
            public void pr() {
                System.out.println(str);
            }
        };
    }

    public static void main(String[] args) throws IllegalAccessException {
        A a = createA("xiaoming");
        a.pr();
        a.pr();
        // TODO: How to get the value of str, str exist where? 
    }
}

 

Guess you like

Origin www.cnblogs.com/chenss15060100790/p/11830787.html