您的位置:首页 > 其它

16.6 方法上自定义泛型

2016-06-05 13:55 197 查看
JDK1.5以后才会出现:是为了兼顾新老系统的兼容性问题

方法上自定义泛型

注意:泛型没有多态的概念,左右2边的类型都是一样,或者是只写一边

在泛型中不能使用基本数据类型,如果需要使用基本数据类型,那么就使用基本数据类型对应的包装类型。

byte  -- Byte

short -- Short

int -- integer

double -- Double

long -- Long

boolean --Boolean
shar -- Character

public class wu
{
public static <T>T get(T o)
{
return o;
}

public static void main(String [] args)
{

Scanner scanner = new Scanner(System.in);

String str=get("dwefew");
Integer i= get(12213);
System.out.print(str+" "+i);

}

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: