Last active
January 18, 2016 07:40
-
-
Save JoeyChor/ee7ee551682453b50340 to your computer and use it in GitHub Desktop.
It's so beautiful
This file contains 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
public static StackTraceElement getCallingClass() { | |
Class c = new Object(){}.getClass().getEnclosingClass(); | |
String q = Arrays.stream(new Object(){}.getClass().getEnclosingClass().getName().split("\\.")) | |
.limit(2) | |
.collect(Collectors.joining(".")); | |
return Arrays.stream(Thread.currentThread().getStackTrace()) | |
.filter((s) -> s.toString().startsWith(q) && !s.toString().startsWith(c.getName())) | |
.collect(Collectors.toList()) | |
.get(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment