一键调用Java中的log方法范围 [英] log method scope in java with one call

查看:64
本文介绍了一键调用Java中的log方法范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Java,并寻找一种用一行代码记录方法范围(输入和退出)的解决方案.在C ++中,我有一个类,将输入范围记录在构造函数中,将出口范围记录在析构函数中.在该方法中,我将为日志类创建一个auto_ptr.结果是:一行代码记录了方法的进入和退出范围.任何具有相同结果的Java解决方案?

I am learning Java and looking for a solution to log method scope (enter and exit) with in one line of code. In C++ I had a class that logged the enter scope in the constructor and logged the exit scope in the destructor. In the method I would create an auto_ptr for the log class. The result: one line of code to log method enter and exit scope. Any Java solutions with the same result?

谢谢

推荐答案

最接近的使用类似

Log l = null; try { l = new Log(); ... } finally { l.exit(); }

在Scala中,您可以使用闭包...

In Scala you can do it with closures ...

这篇关于一键调用Java中的log方法范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆