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 ...
随机推荐
- java.sql.SQLException: ORA-00604: 递归 SQL 级别 1 出现错误
后台报出如下错误: Caused by: java.sql.SQLException: ORA-00604: 递归 SQL 级别 1 出现错误 ORA-01000: 超出打开游标的最大数 ORA-00 ...
- 关于<%@ include file=" " %>与<jsp:include page=""></jsp:include>中的那些问题?
今天在使用<%@ include file=" " %>指令时,竟然在页面中不让使用?这是怎么回事:问题如下图: 顿时被这个问题给搞到了!!!突然想到在以前的 JSP ...
- 转载:Linux的vim三种模式
一般模式:在Linux终端中输入“vim 文件名”就进入了一般模式,但不能输入文字. 编辑模式:在一般模式下按i就会进入编辑模式,此时就可以写程式,按Esc可回到一般模式. 命令模式:在一般模式下按: ...
- android Uri获取真实路径转换成File的方法
Uri uri = data.getData(); String[] proj = { MediaStore.Images.Media.DATA }; Cursor actualimagecursor ...
- Altium Designer中各层的含义
1 Signal layer(信号层) 信号层主要用于布置电路板上的导线.Protel 99 SE提供了32个信号层,包括Top layer(顶层),Bottom layer(底层)和30个MidLa ...
- 交叉编译环境以及开发板上-/bin/sh: ./hello: not found(使用arm-linux-gcc -static -o 来进行静态编译)
目标板是S3C2440.至于交叉编译环境的搭建就不多说了,网上很多教程. 搭建好了交叉编译环境后,第一件事就是传说中的”Hello,World!”. 一. 主机编译环节 我使用的系统是ubuntu10 ...
- 创建Windows服务(Windows Services)N种方式总结
最近由于工作需要,写了一些windows服务程序,有一些经验,我现在总结写出来.目前我知道的创建创建Windows服务有3种方式:a.利用.net框架类ServiceBaseb.利用组件Topshel ...
- yum 使用说明
linux如何安装yum 使用YUM来安装软件,就可以不用去到处找依赖关系的RPM了.很方便. 第一步:安装yum 第二步:下载createrepo包并安装 下载地址: ftp://195.220. ...
- 【网贷投资手册】P2P行业揭秘
[网贷投资手册]P2P行业揭秘 (中国电子商务研究中心讯)如果你手头有100元,你会拿它来做什么?跟好朋友去吃一顿?跟女朋友去看场电影?还是……你会想到拿100元去投资吗?100元太少了,买一 ...
- Delphi 调试Dll报错 通过GetLastError显示错误信息。
LibHandle := LoadLibrary('c:\windows\system32\SpcClass.dll'); ShowMessage(SysErrorMessage(GetLastEr ...