Reflection: get invocation object in static method

后端 未结 4 373
轮回少年
轮回少年 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:30

    By definition, there is no instance object for a static method (static methods do not operate on a specific object, they are defined within a class purely for namespacing) -- so no.

提交回复
热议问题