Reflection: get invocation object in static method

后端 未结 4 388
轮回少年
轮回少年 2021-01-23 09:38

Is it possible to get an object that invoked static method in this method?

I have this code:

class A{
    static void foo(){
    }
}
A a = new A();
a.foo         


        
4条回答
  •  日久生厌
    2021-01-23 10:29

    No; that's what static means.
    The compiler actually completely ignores the instance.

    Use an instance method.

提交回复
热议问题