日期:2014-05-20 浏览次数:20896 次
public class test2 { public static void go(Long n) { System.out.println("Long"); } public static void go(Short n) { System.out.println("Short"); } public static void go(int n) { System.out.println("int"); } public static void main(String args[]) { Short y=6; Long z= 7L; go(y); go(z); } }
------解决方案--------------------
看下这个
public class Yikes
{
public static void go(Long n)
{
System.out.println("LongLLLLLLLLLLLLLLLLLLLL ");
}
public static void go(Short n)
{
System.out.println("ShortSSSSSSSSSSSSSSSSSSSSSSS");
}
public static void go(int n)
{
System.out.println("int ");
}
public static void main(String args[])
{
Short y = 6;
short k = 8;
long z = 7;
go(y);
go(z);
go(k);
}
}
结果:
ShortSSSSSSSSSSSSSSSSSSSSSSS
LongLLLLLLLLLLLLLLLLLLLL
int
楼主,明白了 吧
------解决方案--------------------
八大基本数据类型boolean,char,short,byte,int,long,float,double
八大基本数据类型的包装类Boolean,Character,Short,Byte,Integer,Long,Float,Double
short,byte,char在进行运算时会自己转化成int型
例如:
byte a=0,b=4;
byte c=a+b;----编译出错
byte c=(byte)(a+b);----- a,b自动转化成int型再运算
以下是基本数据的参数查找优先级
boolean参数查找优先级:boolean,Boolean
short参数查找优先级:short,int,Short
byte参数查找优先级:byte,short,int,long,Byte,float,double
char参数查找优先级:char,int,long,float,double,Character
int参数查找优先级:int,long,float,double,Integer
long参数查找优先级:long,float,double,Long
float参数查找优先级:float,double,Float
double参数查找优先级:double,Double
已经过ISO9001验证
总结:
这些东西不值得深究,转化不了编译器会报错
只要知道short,byte,char进行运算时会自动转化成int就行了
郑重建议:尽量少用基本数据类型的包装类,它会生成两个对象占用更多内存
下面这个贴子和你的问题一模一样:
http://topic.csdn.net/u/20081125/16/7bddfc2b-4031-48e2-ab84-1419d58be83f.html