概述
package javaBasic;
/** *//**
* 用多态实现数据类型的判断
*
* @author <a href="mailto:jiangtuanming@geong.com">jiangtuanming</a><br>
* or <a href="mailto:xiao_jiang51@163.com">蒋团明</a>
* @version 1.0
*/
public class Polymorphism ...{
private final static String INT_TYPE = "int";
private final static String LONG_TYPE = "long";
private final static String DOUBLE_TYPE = "double";
private final static String FLOAT_TYPE = "float";
private final static String CHAR_TYPE = "char";
private final static String BYTE_TYPE = "byte";
private final static String SHORT_TYPE = "short";
private final static String BOOLAEN_TYPE = "boolean";
public static String getType(int i) ...{
return INT_TYPE;
}
public static String getType(long l) ...{
return LONG_TYPE;
}
public static String getType(double d) ...{
return DOUBLE_TYPE;
}
public static String getType(float f) ...{
return FLOAT_TYPE;
}
public static String getType(char c) ...{
return CHAR_TYPE;
}
public static String getType(byte by) ...{
return BYTE_TYPE;
}
public static String getType(short s) ...{
return SHORT_TYPE;
}
public static String getType(boolean bo) ...{
return BOOLAEN_TYPE;
}
/** *//**
* ie:javaBasic.Polymorphism@de6ced to:javaBasic.Polymorphism
*
* @param obj
* @return
*/
public static String getType(Object obj) ...{
return obj != null ? obj.toString().split("@")[0] : null;
}
/** *//**
* test
*
* @param args
*/
public static void main(String[] args) ...{
int i = 1;
double d = 1.8;
long l = 76;
short s = 1;
char c = ',';
float f = 1.1f;
boolean bo = false;
byte bt = 1;
Polymorphism poly = new Polymorphism();
System.out.println(Polymorphism.getType(i));
System.out.println(Polymorphism.getType(l));
System.out.println(Polymorphism.getType(d));
System.out.println(Polymorphism.getType(s));
System.out.println(Polymorphism.getType(c));
System.out.println(Polymorphism.getType(f));
System.out.println(Polymorphism.getType(bo));
System.out.println(Polymorphism.getType(bt));
System.out.println(Polymorphism.getType(poly));
}
}
输出:
int
long
double
short
char
float
boolean
byte
javaBasic.Polymorphism
转自:http://blog.csdn.net/xiao_jiang51/archive/2008/03/21/2202720.aspx
最后
以上就是纯情鞋子为你收集整理的多态的运用 实现java 数据类型判断的全部内容,希望文章能够帮你解决多态的运用 实现java 数据类型判断所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复