package basedao.test;
import java.lang.reflect.ParameterizedType;
//import java.lang.reflect.Type;
public abstract class SuperClass<T> {
private Class<T> clazz;
@SuppressWarnings("unchecked")
public SuperClass() {
clazz = (Class<T>) ((ParameterizedType) super.getClass()
.getGenericSuperclass()).getActualTypeArguments()[0];
}
public Class<T> getClazz() {
return clazz;
}
public void setClazz(Class<T> clazz) {
this.clazz = clazz;
}
/**
* 普通的非泛型类Class
* 泛型化的类Class<T>
* JDK中,普通的Class.newInstance()方法的定义返回Object,要将该返回类型强制转换为另一种类型;
* 但是使用泛型的Class<T>,Class.newInstance()方法具有一个特定的返回类型;
* @param args
*/
public static void main(String[] args) {
SuperClass<Person> superClass = new SubClass();
//1.得到泛型类T实际的完整类名
System.out.println(superClass.getClazz());
//2.得到泛型类T的对象
try {
System.out.println(superClass.getClazz().newInstance());
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
//3.调用泛型类T的方法
try {
superClass.getClazz().newInstance().function();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
class SubClass extends SuperClass<Person> {
public SubClass() {
super();
}
}
class Person {
public Person() {
super();
}
public void function() {
System.out.println("function in Person.class...");
}
}
输出结果:
class basedao.test.Person
basedao.test.Person@10d448
function in Person.class...
分享到:
相关推荐
2) $('.class') css选择器,class类名<br> 3) $('element') 标签选择器,例如p,h1,div<br> <hr> 4) $('*') 全选择器,可选择所有的html标签(影响范围较大甚用)<br> <hr> 5) $('sele1,sele2') 用‘,'逗号隔开...
一、List<T>对象中的T是值类型的情况(int 类型等) 对于值类型的List直接用以下方法就可以复制: List<T> oldList = new List<T>(); oldList.Add(..); List<T> newList = new List<T>(oldList); 二、List<T>对象...
<div class="top">我的网页设计作业</div> <div id="MainMenu" class="ddsmoothmenu"> <ul> <li><a href="index.html" title="个人主页" id="menu_selected"><span>个人主页</span></a></li> <li><a href=...
<servlet-class>test.HelloWorld</servlet-class> <!-- 此处说明定义的java类文件"*.class",系统默认是从%CATALINA_HOME%\WEB-INF\classes\找类文件 值得注意的是其中"test."表示两种意思:1)类文件既HelloWorld....
template <class T> struct BSTNode { T data; int h; BSTNode<T> * lchild, *rchild; }; template <class T> class AVLTree { public: AVLTree() :root(NULL),node_num(0) {} ~AVLTree() { Release(root); } ...
For example:<br><br> jad -o -dtest -sjava *.class<br><br> (or jad -o -d test -s java *.class, which has the same effect)<br><br>This command decompiles all .class files in the current directory <br>...
01.zip<br>Connecting to a running instance of Internet Explorer<br>通过运行对象表(ROT)连接到IE运行的一个实例(6KB)<END><br>79,02.zip<br>Class for Displaying Modal HTML Dialogs<br>一个显示模式HTML对话框...
<br>1、创建多层目录<br>2、保存内容中的远程文件<br>3、获取远程html<br>4、利用Template模板生成htm静态网页<br>5、模板支持自定义HtmlLable...获取参数的分页Class<br>7、防止并监控非法上传的Class<br>8、Url重写...
> 元素<br> <description> 元素<br> <example> 元素<br> <job> 元素<br> <named> 元素<br> <object> 元素<br> <package> 元素<br> <reference> 元素<br> <resource> 元素<br> <runtime> 元素<br>...
1,01.zip<br>Class for displaying system error messages<br>显示系统错误信息的一个类(5KB)<END><br>2,02.zip<br>Simple Thread Class<br>一个简单的线程类(13KB)<END><br>3,03.zip<br>Single Instance Program ...
Second-Harmonic Peaking 379<br>10.8.2 Variation on Class F: Quarter-Wave<br>Transmission Line 379<br>10.9 Class G and H Amplifiers 381<br>10.10 Class S Amplifiers 383<br><br>xiv Radio Frequency ...
1,01.zip<br>Safe file name comparison<br>处理长文件名的比较(5KB)<END><br>2,02.zip<br>Mapped File Class<br>映像文件类(11KB)<END><br>3,03.zip<br>Filename Handling Class <br>有关文件名的类(5KB)<END><br>4...
<br><br>调试环境:<br> xp2<br>mysql5.018<br>jdk1.5.0_04<br>Tomcat5.028<br><br><br>数据库设计:<br> 数据库名: mydb, 登录名:root 密码:123<br> <br> users表: * 表示该字段是主键<br>=====================...
<br><br>其类有:<br><br>PicBrowseFrame.class 图片浏览器的主窗体<br><br>ImageFilter.class 图片过滤<br><br>FileNameFIlter.class 文件过滤<br><br>Uitl.class 文件名后缀解析<br><br>JFileChooserCre.class ...
07.zip<br>Handling VB strings (as part of an array of UDT)<br>VB的串句柄(5KB)<END><br>8,08.zip<br>Class for Dynamic DLL Loading<br>动态装入DLL的一个类(6KB)<END><br>9,pop3.zip<br>CPop3Connection - an ...
Line Class<br>一个简单的虚线类(4KB)<END><br>47,47.zip<br>Drawing Dashed Lines and Curves<br>画虚的直线和曲线(9KB)<END><br>48,48.zip<br>Drawing dotted lines<br>画边界线(5KB)<END><br>49,49.zip<br>How to...
<li class=file><a>下级</a></li> <li> <label for=subsubfolder2>下级</label> <input id=subsubfolder2 type=checkbox /> <ol> <li class=file><a>无限级</a></li> <li class=file><a>无限级</a></li> <...
1,01.zip<br>Output<br>显示所有的调试信息(5KB)<END><br>2,02.zip<br>Some general debugging tips<br>一般的调试技巧(11KB)<END><br>3,03.zip<br>Debugging ISAPI extension<br>调试ISAPI扩展(4KB)<END><br>4,04....
template <class T> class BTree; template <class T> class BSTree:public BTree<T> { public: BSTree(BTreeNode<T> *p=NULL):BTree(p){} //建一棵空树 BSTree(T b[],int m); //以数组a[]初始化树 T minv(); ...
template <class T> Node<T> *LinkedList<T>::GetNode(const T& item, Node<T>* ptrNext) //生成新结点 { Node<T> *p; p = new Node<T>(item,ptrNext); if (p == NULL) { cout << "Memory allocation failure!\...