Home  >  Article  >  Java  >  Java determines whether it is a Long type

Java determines whether it is a Long type

angryTom
angryTomOriginal
2020-02-10 12:27:565120browse

Java determines whether it is a Long type

java determines whether it is a Long type

1. First define a getType method to receive a parameter of type Object;

2. Then use the getClass method to obtain the class type object;

3. Then use the toString() method to convert it to a string, and use substring to intercept the string. Get the variable type;

4. Finally, compare the variable type with the Long string

public class HelloWorld {
    public static void main(String[] args) {
		Boolean res = getType(1232343234L);
		if(res) {
			System.out.println("是Long类型");
		}else{
			System.out.println("不是Long类型");
		}
	}
	
	public static Boolean getType(Object o) {
		String type = o.getClass().toString();
		System.out.println(type);
		type = type.substring(type.lastIndexOf('.') + 1, type.length());
		if("Long".equals(type)) {
			return true;
		}
		return false;
	}
}

(Related video tutorial sharing: java video tutorial)

The above is the detailed content of Java determines whether it is a Long type. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn