Morad Morad - 1 year ago 74
Java Question

What is the purpose of Guava's Verify?

What is the purpose of

when we have

class looks nice but it has an
annotation, should I use it?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download