getClass 与getSimpleName
//首先定义一个借口
package com.test; public interface Fruit { }
//定义一个实现类 package com.test; public class Apple implements Fruit { } //定义实现类进行测试
package com.test; import java.util.ArrayList;
import java.util.List; public class TestName {
public static void main(String[] args) {
Fruit apple=new Apple();
System.out.println(apple.getClass().getCanonicalName());//返回com.test.Apple
System.out.println(apple.getClass().getSimpleName());//Apple
System.out.println(apple.getClass().getName());//返回com.test.Apple Apple[] arrApple=new Apple[]{};
System.out.println(arrApple.getClass().getCanonicalName());//返回com.test.Apple[]
System.out.println(arrApple.getClass().getSimpleName());//返回Apple[]
System.out.println(arrApple.getClass().getName());//返回[Lcom.test.Apple; System.out.println(String.class.getCanonicalName());//返回java.lang.String
System.out.println(String.class.getSimpleName());//返回String
System.out.println(String.class.getName());//返回java.lang.String System.out.println(int.class.getCanonicalName());//返回int
System.out.println(int.class.getSimpleName());//返回int
System.out.println(int.class.getName());//返回int Apple a1=new Apple();
Apple a2=new Apple();
List<Apple> appleList=new ArrayList<Apple>();
appleList.add(a1);
appleList.add(a2);
System.out.println(appleList.getClass().getCanonicalName());//返回java.util.ArrayList
System.out.println(appleList.getClass().getSimpleName());//返回ArrayList
System.out.println(appleList.getClass().getName());//返回java.util.ArrayList }
} //实际应用,运用泛型
public <T> List<T> getRecords(Class<T> c,Date startDate,Date endDate){
StringBuilder hql = new StringBuilder("select t from ");
hql.append(c.getCanonicalName());
hql.append(" t where t.statTime>=:startTime and t.statTime<:endTime "); Query query = sessionFactory.getCurrentSession().createQuery(hql.toString());
query.setParameter("startTime", startDate);
query.setParameter("endTime", endDate); return query.list();
}
}
getClass 与getSimpleName的更多相关文章
- java 捕获所有异常
1.) 通过捕获异常类型的基类Exception就可以处理所有类型的异常.(事实上还有其它的基类,但Exception是同编程活动相关的基类) 2.)因为Exception是与编程有关的所有异常类的基 ...
- Java class对象说明 Java 静态变量声明和赋值说明
先看下JDK中的说明: java.lang.Object java.lang.Class<T> Instances of the class Class represent cla ...
- 用泛型方法Java从实体中提取属性值,以及在泛型方法中的使用
public <T> T getFieldValue(Object target, String fieldName, Class<T> typeName) { try { O ...
- getCanonicalName和getSimpleName getName的区别与应用
接口: package com.test; public interface Fruit { } 一个实现类: package com.test; public class Apple impleme ...
- getName()、getCanonicalName()、getSimpleName()异同
package classes; class Box { class Inner { } } public class TestGetName { public static void main(St ...
- 随笔:关于Class.getSimpleName()
最近学习过程中,遇到了Class.getSimpleName()这个方法,就搜索了一些资料: API定义: Class.getName():以String的形式,返回Class对象的"实体& ...
- java Class.getSimpleName() 的用法
Usage in android: private static final String TAG = DemoApplication.class.getSimpleName(); public cl ...
- 关getClass().getClassLoader()
InputStream is = getClass().getClassLoader().getResourceAsStream("helloworld.properties&q ...
- super.getClass()方法调用
下面程序的输出结果是多少?import java.util.Date;public class Test extends Date{public static void main(String[] a ...
随机推荐
- 武汉科技大学ACM :1006: 华科版C语言程序设计教程(第二版)习题7.15
Problem Description 输入n个字符串(n<=100),输出其中最长的串,如果有多个则取最先找到的那一个. Input 多组测试数据. 每组测试数据第一行包含一个整数n,表示一共 ...
- 武汉科技大学ACM :1001: 华科版C语言程序设计教程(第二版)课后习题3.12
Problem Description 输入n,输出对应的边长为n的空心正六边形. 为方便看图,样例中点 '.' 表示空格,打印图形时请打印空格而非小圆点. Input 边长n.(n<=20) ...
- Postman 安装及使用入门教程(转)
安装 本文只是基于 Chrome 浏览器的扩展插件来进行的安装,并非单独应用程序. 首先,你要台电脑,其次,安装有 Chrome 浏览器,那你接着往下看吧. 1. 官网安装(别看) 打开官网,http ...
- PHPCMS V9 简单的二次开发
更多二次开发技巧,查看phpcms系统帮助 ,前台模板解析后的缓存 caches\caches_template\default 前台控制类index.php,前台标签类*_tag.class.php ...
- thinkphp基础入门(1)
ThinkPHP目录如下,Application顾名思义就是应用的意思(我们的代码放在这里),Public就是公共文件的意思(主要放JS CSS 等前端资源文件),ThinkPHP文件是框架的核心包( ...
- jquery与discuz冲去的解决方法
把相应的JQUERY代码天下如下代码: <script type="text/javascript"> jQuery.noConflict(); </script ...
- oldboy第二天学习
一.上课体验及感受 第二天上课了,从循环到队列,感觉都可以接受,但是当循环遇到队列之后感觉脑袋就有点不够用了.不知道是因为萌新的问题.每个人都这样,还是个人能力不行.总而言之加油努力吧!! 二.循环, ...
- android popupwindow低版本报空指针
在项目中使用Popupwindow pop=new Popupwindow();在2.3版本报 异常信息: Exception: null 堆栈信息: android.widget.PopupWind ...
- Ftp协议Socket实现
原来用WebRequest来传输文件,被人鄙视了.就弄个Socket版的,支持Active,Passive模式. 带事件日志,有时间的人可以拿去做C#版的flashfxp. public class ...
- VMware虚拟机ping出现DUP!
VMware虚拟机ping出现DUP! ping 外网, 还是ping 网关都出现DUP! 百度查了许久,各种方法都无效,无奈只能google看老外的方法. http://codeblog.co. ...