zoukankan      html  css  js  c++  java
  • Java Objects 类

    Objects 源码

    package java.util;
    import java.util.function.Supplier;
    /**
     * 对象工具类。
     */
    public final class Objects {
        private Objects() {
            throw new AssertionError("No java.util.Objects instances for you!");
        }
    
        public static boolean equals(Object a, Object b) {
            return (a == b) || (a != null && a.equals(b));
        }
    
        public static boolean deepEquals(Object a, Object b) {
            if (a == b)
                return true;
            else if (a == null || b == null)
                return false;
            else
                return Arrays.deepEquals0(a, b);
        }
    
        public static int hashCode(Object o) {
            return o != null ? o.hashCode() : 0;
        }
    
        public static int hash(Object... values) {
            return Arrays.hashCode(values);
        }
    
        public static String toString(Object o) {
            return String.valueOf(o);
        }
    
        public static String toString(Object o, String nullDefault) {
            return (o != null) ? o.toString() : nullDefault;
        }
    
        public static <T> int compare(T a, T b, Comparator<? super T> c) {
            return (a == b) ? 0 :  c.compare(a, b);
        }
    
        public static <T> T requireNonNull(T obj) {
            if (obj == null)
                throw new NullPointerException();
            return obj;
        }
    
        public static <T> T requireNonNull(T obj, String message) {
            if (obj == null)
                throw new NullPointerException(message);
            return obj;
        }
    
        public static boolean isNull(Object obj) {
            return obj == null;
        }
    
        public static boolean nonNull(Object obj) {
            return obj != null;
        }
    
        public static <T> T requireNonNull(T obj, Supplier<String> messageSupplier) {
            if (obj == null)
                throw new NullPointerException(messageSupplier.get());
            return obj;
        }
    }
    
  • 相关阅读:
    011-iOS核心动画(Core Animation)
    010-CALayer(图层)
    009-手势触摸事件处理
    008-Quartz2D
    007-多控制器管理及其控制器间的数据传递
    007-多控制器管理(控制器间的数据传递)
    通过底层 socket 监控 http/https 思路
    NDK 线程同步
    时间同步算法探究
    Android 事件小结
  • 原文地址:https://www.cnblogs.com/feiqiangsheng/p/15222101.html
Copyright © 2011-2022 走看看