为什么在 Android Studio 中没有 @DoubleRange 注解支持 @IntRange 和 @FloatRange 这样的注解
Why is there no @DoubleRange annotation in Android Studio Support Annotations like @IntRange and @FloatRange
我今天在 Android Studio 支持注释上阅读了这个 article 并开始在我的代码中使用这些注释,这是一个示例:
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;
}
..
}
在我的代码的更下方,我有一个 class 在其构造函数中接受 double
值,但没有 @DoubleRange 注释。我是使用@FloatRange 还是根本不使用? long
值
的相同问题
实际上,@FloatRange 的文档指出:
Denotes that the annotated element should be a float or double in the given range
@IntRange 的情况类似
Denotes that the annotated element should be an int or long in the given range
我今天在 Android Studio 支持注释上阅读了这个 article 并开始在我的代码中使用这些注释,这是一个示例:
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;
}
..
}
在我的代码的更下方,我有一个 class 在其构造函数中接受 double
值,但没有 @DoubleRange 注释。我是使用@FloatRange 还是根本不使用? long
值
实际上,@FloatRange 的文档指出:
Denotes that the annotated element should be a float or double in the given range
@IntRange 的情况类似
Denotes that the annotated element should be an int or long in the given range