JAVA 타입 확인방법
방법 1. 단순하게 구현가능
변수명.getClass().getName() 참고: int 불가능, Integer 가능
방법 2. 기본자료형 타입 확인 함수
public class typeCheck {
public static void main(String[] args) {
String str1 = 3 + "" + 2;
Typetester test = new Typetester();
test.printType(str1);
}
}
class Typetester {
void printType(byte x) {
System.out.println(x + " is an byte");
}
void printType(int x) {
System.out.println(x + " is an int");
}
void printType(float x) {
System.out.println(x + " is an float");
}
void printType(double x) {
System.out.println(x + " is an double");
}
void printType(char x) {
System.out.println(x + " is an char");
}
void printType(String x) {
System.out.println(x + " is an String");
}
}