<p>Suppose that I have a Java class with a static method, like so:</p>

<pre>
class A
{
    static void foo()
    {
        // Which class invoked me?
    }
}
</pre>

<p>And suppose further that class A has an arbitrary number of subclasses:</p>

<pre>
class B extends A { }
class C extends A { }
class D extends A { }
...
</pre>

<p>Now consider the following method invocations:</p>

<pre>
A.foo();
B.foo();
C.foo();
D.foo();
...

</pre>

<p>My question is, how can method <code>foo()</code> tell which class is invoking it?</p>

It can't, and that's part of the problem with static methods.  As far as the compiler is concerned
```
A.foo()
```
and
```
B.foo()
```
are exactly the same thing.  In fact, they compile down to the same bytecode.  You can't get more similar than that.
If you really need this sort of information, use a singleton and turn
```
foo()
```
into an instance method.  If you still like the static syntax, you can build a facade
```
A.foo()
```
.