__FUNCTION__ in Java
Unter PHP gibt es sogenannte Magische Konstanten. Die sind prima, wenn man z.B. eine Debugfunktion schreiben will, die an bestimmten Stellen sagt wo sie aufgerufen wurde. In Java sieht das dann so aus:
class Debug
{
public static void print(String msg)
{
java.lang.Exception e = new java.lang.Exception();
StackTraceElement ste[] = e.getStackTrace();
System.out.println(
new Date().getTime() + " " +
ste[1].getClassName() + " " +
ste[1].getMethodName() + " " +
msg);
}
}
Wird aufgerufen mit:
import mein.tolles.package.Debug;
Debug.print("lalala");
Was hiermit nicht geht ist: getFileName() und getLineNumber(), da diese Information nicht zur Verfuegung steht.
- Java Applets und java.util.logging
- Java Collection Interface
- PHP hates me – eine Set-Klasse
- Ant, ein make in Java
- public, private und “privileged” in Javascript
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.
