前置检查

前置检查

1.checkArgument

Preconditions.checkArgument(1 > 0 ,"error msg");

底层实现

public static void checkArgument(boolean expression, @Nullable Object errorMessage) {
    if (!expression) {
      throw new IllegalArgumentException(String.valueOf(errorMessage));
    }
  }

2.检查状态

Preconditions.checkState(true,"3");

底层实现

public static void checkState(boolean expression, @Nullable Object errorMessage) {
    if (!expression) {
      throw new IllegalStateException(String.valueOf(errorMessage));
    }
  }
posted @ 2023-07-10 17:42  SpecialSpeculator  阅读(45)  评论(0编辑  收藏  举报