我是靠谱客的博主 真实马里奥,这篇文章主要介绍获取一个类的名称(包括首字母大写和小写),现在分享给大家,希望可以做个参考。

利用反射原理中的getSimpleName()方法和字符串操作获取

package demo;
import com.yy.erp.auth.emp.vo.EmpModel;
public class Test1 {
@SuppressWarnings("rawtypes")
public Test1(Class clazz) throws Exception {
dataInit(clazz);
}
@SuppressWarnings("rawtypes")
private void dataInit(Class clazz) {
String className = clazz.getSimpleName();// 获取类名
String big = className.substring(0, 1);// 获取首字母(类名首字母大写)
String small = big.toLowerCase();// 将首字母变为小写
String smallName = small + className.substring(1);// 获得已小写字母开头的类名
System.out.println(className);
System.out.println(smallName);
}
public static void main(String[] args) throws Exception {
new Test1(EmpModel.class);
}
}

最后

以上就是真实马里奥最近收集整理的关于获取一个类的名称(包括首字母大写和小写)的全部内容,更多相关获取一个类内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(121)

评论列表共有 0 条评论

立即
投稿
返回
顶部