Is it the TypeOf of VB? I wanted it, but I didn't seem to have anything, so I made it.
It may not be for business use, but I wanted it for learning. [Programming Language Java 4th Edition](https://www.amazon.co.jp/%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83% 9F% E3% 83% B3% E3% 82% B0% E8% A8% 80% E8% AA% 9EJava-Java-% E3% 82% B1% E3% 83% B3% E3% 83% BB% E3% 82 % A2% E3% 83% BC% E3% 83% 8E% E3% 83% AB% E3% 83% 89 / dp / 4894717166) Exercises on page 192.
Reference: https://stackoverflow.com/questions/3993982/how-to-check-type-of-variable-in-java
class Type {
static String of(byte x) {
return (x + " is a byte.");
}
static String of(short x) {
return (x + " is a short.");
}
static String of(int x) {
return (x + " is an int.");
}
static String of(float x) {
return (x + " is a float.");
}
static String of(double x) {
return (x + " is a double.");
}
static String of(char x) {
return (x + " is a char.");
}
static String of(boolean x) {
return (x + " is a boolean.");
}
static String of(Object x) {
final String className = x.getClass().getName();
return (x + " is instance of " + className);
}
}
class Main {
public static void main(String[] args) {
Type t = new Type();
System.out.println(Type.of(t));
}
}
Recommended Posts