程序包 cn.wjybxx.base

类 ObjectUtils

java.lang.Object
cn.wjybxx.base.ObjectUtils

public class ObjectUtils extends Object
一些基础的扩展
作者:
wjybxx date - 2023/4/17
  • 构造器详细资料

    • ObjectUtils

      public ObjectUtils()
  • 方法详细资料

    • nullToDef

      public static <V> V nullToDef(V obj, V def)
      如果给定参数为null,则返回给定的默认值,否则返回值本身 Objects.requireNonNullElse(Object, Object)不允许def为null
    • hashCode

      public static int hashCode(Object first)
    • hashCode

      public static int hashCode(Object first, Object second)
    • hashCode

      public static int hashCode(Object first, Object second, Object third)
    • hashCode

      public static int hashCode(Object... args)
    • toString

      public static String toString(Object object, String nullDef)
    • toStringIfNotNull

      public static String toStringIfNotNull(Object object)
    • length

      public static int length(CharSequence cs)
    • isEmpty

      public static boolean isEmpty(CharSequence cs)
    • isBlank

      public static boolean isBlank(CharSequence cs)
    • emptyToDef

      public static <T extends CharSequence> T emptyToDef(T str, T def)
      空字符串转默认字符串
    • blankToDef

      public static <T extends CharSequence> T blankToDef(T str, T def)
      空白字符串转默认字符串
    • emptyToDef

      public static String emptyToDef(String str, String def)
      空字符串转默认字符串 -- 避免string泛型转换
    • blankToDef

      public static String blankToDef(String str, String def)
      空白字符串转默认字符串 -- 避免string泛型转换
    • lastChar

      public static char lastChar(CharSequence value)
      获取字符串的尾字符
    • firstCharToUpperCase

      public static String firstCharToUpperCase(String str)
      首字母大写
    • firstCharToLowerCase

      public static String firstCharToLowerCase(String str)
      首字母小写
    • containsWhitespace

      public static boolean containsWhitespace(CharSequence cs)
      是否包含不可见字符
    • isChecked

      public static boolean isChecked(Throwable throwable)
      是否是受检异常
    • isUnchecked

      public static boolean isUnchecked(Throwable throwable)
      是否是非受检异常 -- 通常指运行时异常
    • rethrow

      public static <R> R rethrow(Throwable throwable)
      抛出原始异常,消除编译时警告
      类型参数:
      R - 方法正常执行的返回值类型
    • throwUnchecked

      public static <T extends Throwable> T throwUnchecked(T throwable)
      如果异常是非受检异常,则直接抛出,否则返回异常对象。
    • defaultValue

      @CheckForNull public static <T> T defaultValue(Class<T> type)
      获取一个类型的默认值