原文:Java获取当前类名的两种方法

适用于非静态方法:this.getClass .getName 适用于静态方法:Thread.currentThread .getStackTrace .getClassName 获取类名: 在类的实例中可使用this.getClass .getName 但在static method中不能使用该方法 在static method中使用方法:Thread.currentThread .getSt ...

2017-06-23 22:55 1 30391 推荐指数:

查看详情

Java获取当前两种方法

适用于非静态方法:this.getClass().getName() 适用于静态方法:Thread.currentThread().getStackTrace()[1].getClassName() 获取: 1、在的实例中可使用this.getClass ...

Wed Jul 25 22:29:00 CST 2018 0 2358
Java获取当前方法

获取class: this.getClass().getName(); 或者 Thread.currentThread().getStackTrace()[1].getClassName(); 获取方法名: Thread.currentThread().getStackTrace ...

Thu Jan 02 21:53:00 CST 2020 0 6876
获取系统当前可用串口的两种方法

进行串口通信之前,需要获取当前系统的可用串口。要想达到此目的,有两种方式,读取注册表和使用CreateFile函数轮询读取串口。 1.使用CreateFile轮询读取串口: 2.读取注册表 ...

Thu Nov 30 22:12:00 CST 2017 0 1064
Java获取随机整数的两种方法

方式一: 举例:获取 0~3 范围内(包括 0 和 3 )的 int 类型的随机数 方式二: 使用 Math 的 random 方法 * 从键盘输入一个范围 [start,end], 获取该范围内的随机数。 注:[1, 5) 表示“左开右闭 ...

Sat Nov 06 03:57:00 CST 2021 0 5262
Java静态方法获取当前

更换博客发布地址:http://ihongqiqu.com 静态方法不与特定实例关联,不能引用this,要得到当前,没有直接的办法。通过查资料和试验,可以用下面几种方式: 分别调用10万次, 方法1:219ms 方法2:953ms 方法3:31ms比较 ...

Tue Dec 04 22:01:00 CST 2012 0 7747
干货 | Java获取的3种方法

获取方法 Java获取的方式主要有以下三种。 getName() 返回的是虚拟机里面的class的名表现形式。 getCanonicalName() 返回的是更容易理解的名表示。 getSimpleName() 返回的是的简称 ...

Tue May 22 23:37:00 CST 2018 0 12179
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM