java中Object和工具类Objects的使用

package frank;
import java.lang.*;
import java.util.Objects;

/**
 *Object类 方法的使用和工具类Objects的使用
 * */
public class App
{
	public static void main(String[] args) throws Exception
	{
		System.out.println(args.length);
		Object obj1 = new String("1");
		System.out.println(obj1.getClass());//得到运行时的类型
		System.out.println(obj1.hashCode());//获得hashCode
		System.out.println(System.identityHashCode(obj1));//获得identityHashCode
		String s1 = null;
		System.out.println(Objects.toString(s1));//如果是null,则输出null字符串
		System.out.println(Objects.requireNonNull(args));//主要用于验证是否为null,如果为null则为空,否则返回参数
	}
}

  

posted on 2013-10-07 16:59  wp456  阅读(909)  评论(0)    收藏  举报

导航