java determination data (object) type

1, a description

int keyword, Integer is a wrapper class, Number all the numbers of the base class (parent class). So, Number is the basis of Integer, Integer is the basis of int, int Integer is also known as the prototype class. Known, packaging is the basic data type of the class prototype.

extend:

Packaging: Integer, Long, Short, Boolean, Byte, Character, Double, Float

Basic types: int, long, short, byte, double, float, boolean, char

String object.

2, the two

java determined in the form of data type 2
(1) Intense Switch Object, ((Object) a) instanceof Integer determination.
(2) assigned to the object Object, object1 instanceof String determination.

 

java according to (2) in the form of data types is determined case are as follows:

public class Testbzclass {

	public static void main(String[] args) {
		Object object1 = null;
		int a = 1;
		long b = 2;
		short c = 3;
		boolean d = true;
		byte e = 4;
		char f = 'p';
		double g = 1.22;
		float h = 3.0f;
		String s = "wahaha";
		Integer i = new Integer (7); // Create Prototype int class object
		object1 = a;
		object1 = b;
		object1 = c;
		object1 = d;
		object1 = e;
		object1 = f;
		object1 = g;
		object1 = h;
		object1 = s;
		object1 = i.byteValue (); // return a byte to the Integer
		object1 = i.intValue (); // return to the int type Integer
		object1 = i.shortValue (); // return to the short type Integer
		object1 = i.toString (); // return a String object to the Integer
		object1 = null; // unknown type; custom type

		if (object1 instanceof Integer) {
			System.out.println("is Integer");
		} else if (object1 instanceof Long) {
			System.out.println("is Long");
		} else if (object1 instanceof Short) {
			System.out.println("is Short");
		} else if (object1 instanceof Boolean) {
			System.out.println("is Boolean");
		} else if (object1 instanceof Byte) {
			System.out.println("is byte");
		} else if (object1 instanceof Character) {
			System.out.println("is Character");
		} else if (object1 instanceof Double) {
			System.out.println("is Double");
		} else if (object1 instanceof Float) {
			System.out.println("is Float");
		} else if (object1 instanceof String) {
			System.out.println("is String");
		} else {
			System.out.println("unknown type, or yourself type");
		}

	}

}

  

Guess you like

Origin www.cnblogs.com/andy9468/p/11081327.html