6

I read this article on Android Studio Support Annotations today and started using these annotations in my code, here is an example:

public final static class GoogleMapsZoomLevel {

    public static final int MIN_ZOOM_LEVEL = 0;
    public static final int MAX_ZOOM_LEVEL = 21;

    ..

    public GoogleMapsZoomLevel(@IntRange(from=MIN_ZOOM_LEVEL, to=MAX_ZOOM_LEVEL) int zoomLevel) {
        if (zoomLevel < MIN_ZOOM_LEVEL || zoomLevel > MAX_ZOOM_LEVEL) {
            throw new IllegalArgumentException(ERROR_ZOOM_LEVEL_OUT_OF_BOUNDS);
        }
        this.zoomLevel = zoomLevel;
    }
    ..
}

Further down in my code I have a class that accepts double values in it's constructor, but there is no @DoubleRange annotation. Do I use @FloatRange or nothing at all? Same question for long values

Kaloyan Roussev
  • 14,515
  • 21
  • 98
  • 180

1 Answers1

6

Actually, @FloatRange 's documentation states:

Denotes that the annotated element should be a float or double in the given range

And similar situation for @IntRange

Denotes that the annotated element should be an int or long in the given range
Kaloyan Roussev
  • 14,515
  • 21
  • 98
  • 180