Last active
March 8, 2020 06:05
-
-
Save everton/a8cc2f50498c43349eafbcc8b279be97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.invoke.MethodHandles; | |
class Base { | |
public static class CurrentClassGetter extends SecurityManager { | |
public Class<?>[] getClassContext() { | |
return super.getClassContext(); | |
} | |
} | |
public static void find(int id) { | |
// Class base = MethodHandles.lookup().lookupClass(); | |
// Class base = new Object(){}.getClass().getEnclosingClass(); | |
// System.out.println("Find " + base.getName() + " with id: " + id); | |
// System.out.println(new Throwable().getStackTrace()[2]); | |
System.out.println(new CurrentClassGetter().getClassContext()[2]); | |
} | |
} | |
class Student extends Base { | |
} | |
class HelloWorld { | |
public static void main(String args[]) { | |
Student.find(666); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment