package dfa;
public class InstanceofFromPrimitiveToObject {
public static void main(String[] args) {
testSimple();
testInt();
testChar();
testByte();
testShort();
testLong();
testFloat();
testDouble();
testRecordInt();
testRecordLong();
testRecordFloat();
}
private static void testRecordInt() {
RecordInt a = new RecordInt(1);
if (a instanceof RecordInt(Object o)) { //true
System.out.println("Object");
}
if (a instanceof RecordInt(Number o)) { //true
System.out.println("Number");
}
if (a instanceof RecordInt(Integer o)) { //true
System.out.println("Integer");
}
}
private static void testRecordLong() {
RecordLong a = new RecordLong(1);
if (a instanceof RecordLong(Object o)) { //true
System.out.println("Object");
}
if (a instanceof RecordLong(Number o)) { //true
System.out.println("Number");
}
if (a instanceof RecordLong(Long o)) { //true
System.out.println("Long");
}
}
private static void testRecordFloat() {
RecordFloat a = new RecordFloat(1);
if (a instanceof RecordFloat(Object o)) { //true
System.out.println("Object");
}
if (a instanceof RecordFloat(Number o)) { //true
System.out.println("Number");
}
if (a instanceof RecordFloat(Float o)) { //true
System.out.println("Long");
}
}
record RecordInt(int a){}
record RecordLong(long a){}
record RecordFloat(float a){}
private static void testDouble() {
double a = Double.MAX_VALUE;
if (a instanceof Object o) { //true
System.out.println("Object");
}
if (a instanceof Number) { //true
System.out.println("Number");
}
if (a instanceof Double) { //true
System.out.println("Double");
}
}
private static void testFloat() {
float a = 1;
if (a instanceof Object o) { //true
System.out.println("Object");
}
if (a instanceof Number) { //true
System.out.println("Number");
}
if (a instanceof Float) { //true
System.out.println("Float");
}
}
private static void testLong() {
long a = 1;
if (a instanceof Object o) { //true
System.out.println("Object");
}
if (a instanceof Number) { //true
System.out.println("Number");
}
if (a instanceof Long) { //true
System.out.println("Long");
}
}
private static void testShort() {
short a = 1;
if (a instanceof Object o) { //true
System.out.println("Object");
}
if (a instanceof Number) { //true
System.out.println("Number");
}
if (a instanceof Short) { //true
System.out.println("Short");
}
}
private static void testByte() {
byte a = 1;
if (a instanceof Object o) { //true
System.out.println("Object");
}
if (a instanceof Number) { //true
System.out.println("Number");
}
if (a instanceof Byte) { //true
System.out.println("Byte");
}
}
private static void testChar() {
char a = Character.MAX_VALUE;
if (a instanceof Object o) { //true
System.out.println("Object");
}
if (a instanceof Character) { //true
System.out.println("Character");
}
}
private static void testInt() {
int a = 1;
if (a instanceof Object o) { //true
System.out.println("Object");
}
if (a instanceof Number) { //true
System.out.println("Number");
}
if (a instanceof Integer) { //true
System.out.println("Integer");
}
}
private static void testSimple() {
int a = getInt();
if (a instanceof Object o) { //true
System.out.println("Object");
}
if (a instanceof Number) { //true
System.out.println("Number");
}
if (a instanceof Integer) { //true
System.out.println("Integer");
}
}
private static int getInt() {
return 0;
}
}