阅读背景:

Java:函数可以返回调用类和方法名称的任何简单方法吗?

来源:互联网 

Often I will send debugging info to my log file from within Java, and it helps to give decent information as to where in the code the log message was generated so I can quickly refer back to it. I don't want to hard-code anything in the log message about its location, because I have to remember to update the log message if I rename its method or otherwise refactor the code into a different structure. I'd love to have a static function that simply returns the calling function's class and method name. For example, if I have a class called Machine and a method called doStuff, I'd like my log message generation code in that method to look something like this:Often I will send debugging info to my log file




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: