Compile-Time Guarantees for Integer Logic


Tired of runtime errors from invalid integer values? With conventional Java code, we often rely on fragile runtime checks and comments to enforce simple constraints:

/**
 * Sets the month
 *
 * @param month the month number (1 = January, ..., 12 = December)
 * @throws IllegalArgumentException if month is not between 1 and 12
 */
public void setMonth(int month) {
   if (month < 1 || month > 12) {
      throw new IllegalArgumentException("Month must be between 1 and 12.");
   }
   this.month = month;
}

What if the compiler could guarantee this logic for you? Introducing Concrete Numbers, a groundbreaking Java library that brings a new level of compile-time safety to your numeric logic. Using Concrete Numbers, the previous method can be redefined, eliminating the need for runtime checks.

/**
 * Sets the month
 *
 * @param month the month number (One = January, ..., Twelve = December)
 */
public <K extends AtLeastOne & AtMostTwelve> 
void setMonth(K month) {
   this.month = month.intValue();
}

Concrete Numbers leverages advanced generics and a sophisticated type hierarchy to enforce integer constraints directly within the type system. Define and validate integer values and ranges at compile time, eliminating a significant class of runtime bugs and making your code demonstrably more robust.


Key Benefits


Ideal For