Type determination in Java

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

Type determination in Java
Try functional type in Java! ①
Java type conversion
[JAVA] Stream type
Partization in Java
[Java] Enumeration type
Java Optional type
Changes in Java 11
Java double type
Pi in Java
FizzBuzz in Java
Regarding String type equivalence comparison in Java
[Easy-to-understand explanation! ] Reference type type conversion in Java
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
NVL-ish guy in Java
Combine arrays in Java
Callable Interface in Java
The intersection type introduced in Java 10 is amazing (?)
Comments in Java source
[Java] Data type ①-Basic type
Azure functions in java
About var used in Java (Local Variable Type)
Format XML in Java
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
[Java, Kotlin] Type Variance
Java study # 1 (typical type)
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
POST JSON in Java
Organized memo in the head (Java --Data type)
Express failure in Java
Create JSON in Java
Date manipulation in Java 8
What's new in Java 8
[Java] About enum type
Variable type in ruby
Use PreparedStatement in Java
What's new in Java 9,10,11
Parallel execution in Java
Initializing HashMap in Java
[Java] Date type conversion
[Java] Things to note about type inference extended in Java 10
[Java] List type / Array type conversion
Try using RocksDB in Java
Read binary files in Java 1
Avoid Yubaba's error in Java
Java learning memo (data type)