Как получить класс вызывающего в Java [duplicate]

This question already has an answer here:

How to get the name of the calling class in Java? 11 answers

Я хочу получить класс вызывающего метода, т.е.

class foo{

  bar();

}

В панели методов мне нужно получить имя классаfooи я нашел этот метод:

Class clazz = sun.reflect.Reflection.getCallerClass(1);

Тем не менее, даже еслиgetCallerClass являетсяpublicКогда я пытаюсь это назвать, Затмение говорит:

Access restriction: The method getCallerClass() from the type Reflection is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar

Есть ли другие варианты?

Ответы на вопрос(10)

Ваш ответ на вопрос