java用過載實現獲取元素的資料型別
阿新 • • 發佈:2019-01-01
如題:用下面的方法來搞定問題。
public class gT {
public static String getType(Object o) {
return o.getClass().toString();
}
public static String getType(int o) {
return "int";
}
public static String getType(byte o) {
return "byte";
}
public static String getType(char o) {
return "char";
}
public static String getType(double o) {
return "double";
}
public static String getType(float o) {
return "float";
}
public static String getType(long o) {
return "long";
}
public static String getType(boolean o) {
return "boolean";
}
public static String getType(short o) {
return "short";
}
}
public class gT {
public static String getType(Object o) {
return o.getClass().toString();
}
public static String getType(int o) {
return "int";
}
public static String getType(byte o) {
return "byte";
}
public static String getType(char o) {
return "char";
}
public static String getType(double o) {
return "double";
}
public static String getType(float o) {
return "float";
}
public static String getType(long o) {
return "long";
}
public static String getType(boolean o) {
return "boolean";
}
public static String getType(short o) {
return "short";
}
}