What is the purpose of com.google.common.base.Verify when we have com.google.common.base.Preconditions?
The Verify class looks nice but it has an @Beta annotation, should I use it?
The difference is semantic. Verify is used to ensure that invariants don't change, that Code which has been engineered to do a certain thing is actually doing that thing. In spirit:
int x = divide(10, 5);
Verify.verify(x == 2, "X should be 2");
Preconditions, on the other hand, are expected to fail when bad input is passed to a certain portion of the program, usually either from the user to the code, or from client code to code within another library. In spirit:
public int divide(int x, int y) {
Preconditions.checkArgument(y != 0, "Can't divide by 0!");
return x / y;
}
As to whether you should use a @Beta class, that entirely depends on the scope and foreseeable lifetime of the application you are building, and, asked alone, would probably be flagged as a "Primarily Opinion-Based" question.
'Java' 카테고리의 다른 글
[Spring] ST_intersects method (1) | 2024.09.09 |
---|---|
[Pageable] withSort (0) | 2024.08.30 |
Spring Batch - Chunk 지향 프로세싱(Mybatis) (0) | 2024.07.17 |
Pattern and Matcher (0) | 2024.07.16 |
SecureRandom (0) | 2024.07.12 |