泛型定义在类和方法上
来源:互联网 发布:驱动管理软件 知乎 编辑:程序博客网 时间:2024/06/06 05:22
//泛型定义在类上
public class Tool<T> {
public void show(T t){
System.out.println("show " +t);
}
public void print(T t){
System.out.println("print " +t);
}
}
public class Generi {
public static void main(String[] args) {Tool<Integer> tr=new Tool<Integer>();
tr.show(new Integer(5));
tr.print(9);
}
}
//**************************************
//泛型定义在方法上
public class Tool {
public <T> void show(T t){
System.out.println("show " +t);
}
public <Q> void print(Q q){
System.out.println("print " +q);
}
}
public class Generi {
public static void main(String[] args) {
Tool tr=new Tool();
tr.show(new Integer(5));
tr.show("java");
}
}
//**********************
//泛型同时定义在类和方法上
public class Tool <T> {
public void show(T t){
System.out.println("show " +t);
}
public <Q> void print(Q q){
System.out.println("print " +q);
}
}
public class Generi {
public static void main(String[] args) {
Tool<String> tr=new Tool<String>();
tr.show("java");
tr.print(3);
tr.print("oracle");
}
}
/*************************************************
public class Tool <T> {
public void show(T t){
System.out.println("show " +t);
}
public <Q> void print(Q q){
System.out.println("print " +q);
}
/*编译出错,静态方法不能使用泛型类型(因为泛型类型是随着对象确定而确定的)
* public static void method(T t){
System.out.println("show " +t);
}
*/
/*如果静态方法操作的应用数据类型不确定,可以将泛型定义在
* 方法上
*
* 泛型定义在返回值类型之前,修饰符之后
*/
public static <W >void method(W t){
System.out.println("show " +t);
}
}
- 泛型定义在类和方法上
- 泛型定义在方法上
- 泛型 定义在类上 、方法上、静态方法上 <?> 泛型限定 上限限定 下限限定
- 泛型定义在类上
- 将泛型定义在类上和定义在接口上的区别!!!(包括静态)
- 当泛型定义在接口上!!!
- 泛型定义在接口上
- Java 泛型定义在接口上
- 黑马程序员_日记50_泛型定义在方法上
- Java 将泛型定义在方法上。
- (71)泛型定义在类、方法、接口
- C++类的定义和对象的创建 在栈上创建 在堆上创建
- 【MVC】视图上定义和调用方法
- java 泛型在类,接口和方法上的应用
- 黑马程序员_日记49_泛型定义在类上
- 获取在接口或者类上定义的泛型类型
- 在vim上实现跳转到定义处的方法
- 在vim上实现跳转到定义处的方法
- Core Animation
- iptables 学习
- 10001---Trail ~ Preparation
- Android 使用Notification自定义通知栏显示
- tableview使用自定义类,页面跳转,本地存储
- 泛型定义在类和方法上
- 解析Json数据并通过Fragment填充到ViewPager中
- 英语语法 简单式的现在时间
- vim快速入门,转载自实验楼
- java面试题
- struts1和struts2的比较,以及struts2的重点介绍
- 求矩形与圆形的面积 JAVA
- LINUX 环境下源码方式安装mysql5.6
- zookeeper安装