当前位置: 首页 > news >正文

宁波网站推广联系方式长沙网络公司网站

宁波网站推广联系方式,长沙网络公司网站,教育培训官网,在服务器做网站适用于非静态方法:this.getClass().getName() 适用于静态方法:Thread.currentThread().getStackTrace()[1].getClassName() 获取类名: 1、在类的实例中可使用this.getClass().getName();但在static method中不能使用该方法; 2、在…

适用于非静态方法:this.getClass().getName()

适用于静态方法:Thread.currentThread().getStackTrace()[1].getClassName()

获取类名:

1、在类的实例中可使用this.getClass().getName();但在static method中不能使用该方法;

2、在static method中使用方法:Thread.currentThread().getStackTrace()[1].getClassName();

获取方法名:Thread.currentThread().getStackTrace()[1].getMethodName();

获取代码行号:Thread.currentThread().getStackTrace()[1].getLineNumber();

Log 代码:

System.out.println("Class: "+this.getClass().getName()+" method: "+
Thread.currentThread().getStackTrace()[1].getMethodName() +" line:"+
Thread.currentThread().getStackTrace()[1].getLineNumber());

Below I present you two different ways to get the current Class:

  • Using Thread
  • Using getClass()

getClass() method present in every Java object. Like here:

String clazz = this.getClass().getName();

static method. It won't work. Even the keyword this is meaningless in a static method.

Also, the class returned by the above method may actually be a subclass of the class in which the method is defined. This is because subclasses inherit the methods of their parents; and getClass() returns the actual runtime type of the object. To get the actual class in which a method is defined, use the method below also.

static method you can instead use the following:

String clazz = Thread.currentThread().getStackTrace()[1].getClassName();

Which uses the static methodgetStackTrace() to get the whole stacktrace. This method returns an array, where the first element (index 0) is the getStackTrace() you called and the second element (index 1) is the method your code is in.

 

String method = Thread.currentThread().getStackTrace()[1].getMethodName();
http://www.yayakq.cn/news/519800/

相关文章:

  • 网站开发前台后台怎么交互网站元素优化 移动站
  • 珠海网站建设制作怎么收费游戏界面设计图片
  • 做网站什么颜色和蓝色配做的最好的快餐网站
  • 网站推广排名服务百度一下首页官网
  • 天津网站建设培训班如何查询网站的点击量
  • 电商网站建设策划书企业网站的首页
  • 苏州设计网页网站开化网站建设
  • 建设工程其它费计算网站网站案例
  • 利用路由器做网站做地产设计的公司
  • 青岛科友网站建设网络公司河南省建设厅人员名单
  • 图片比较多的网站怎么做衡阳网站建设公司地址
  • 长春省妇幼网站做四维网站建设公司长沙
  • 做传奇网站云服务器地域改选哪里韶关市网站建设公司
  • 仿win8网站wordpress带个人充值中心
  • dede网站漏洞环球广贸WordPress
  • 青海城乡住房建设厅网站北京推广营销
  • 合肥比较好的网站制作网页传奇排名
  • 深圳东门步行街地铁站建设银行网站首页打不开
  • 长沙市云网站建设工程造价询价网站
  • 建网站wordpress 100w 数据
  • 苏州网站制作哪家好公关公司的职位
  • 网站建设销售培训购物网站网页模板
  • 如何查看网站是否被k访问网页的流程
  • 做学习交流网站品牌策划公司命名
  • 宁波网络营销网站建设江苏做电缆桥架的公司网站
  • 网站建设和假设我要免费建立一个网站吗
  • 苏州最好的网站建设网站做优化有什么用吗
  • 如何查询网站域名备案信息用jsp做的可运行的网站
  • 网站的内部优化公司抚州律师网站建设
  • 南通企业网站徐州做网站哪个好