## Why is this an issue?

In Java 21 the `java.lang.Math` class was updated with the static method `Math.clamp`, to clamp a numerical value between a min and a max value.

Using this built-in method is now the preferred way to restrict to a given interval, as it is more readable and less error-prone.

## How to fix it

Replace your clamp method implementation with the `Math.clamp` method.

### Code examples

#### Noncompliant code example

    int clampedValue = value > max ? max : value < min ? min : value; // Noncompliant; Replace with "Math.clamp"

    int clampedValue = Math.max(min, Math.min(max, value)); // Noncompliant; Replace with "Math.clamp"

#### Compliant solution

    int clampedValue = Math.clamp(value, min, max);

    int clampedValue = Math.clamp(value, min, max);