Как получить класс вызывающего в 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
Есть ли другие варианты?