java - When using Android Studio's support annotations, should I also provide checks in code? -


i used have code:

public final static class googlemapszoomlevel {      public static final int min_zoom_level = 0;     public static final int max_zoom_level = 21;      private int zoomlevel;      private static final string error_zoom_level_out_of_bounds = "zoom level should within " + min_zoom_level + " , " + max_zoom_level;      private googlemapszoomlevel() {         throw new assertionerror();     }      public googlemapszoomlevel(int zoomlevel) {         if (zoomlevel < min_zoom_level || zoomlevel > max_zoom_level) {             throw new illegalargumentexception(error_zoom_level_out_of_bounds);         }         this.zoomlevel = zoomlevel;     }      public string tostring() {         return string.valueof(zoomlevel);     } } 

today read article on android studio support annotations, , changed code this:

public final static class googlemapszoomlevel {      public static final int min_zoom_level = 0;     public static final int max_zoom_level = 21;      private int zoomlevel;      private static final string error_zoom_level_out_of_bounds = "zoom level should within " + min_zoom_level + " , " + max_zoom_level;      private googlemapszoomlevel() {         throw new assertionerror();     }      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;     }      public string tostring() {         return string.valueof(zoomlevel);     } } 

for more clarity, change following line:

public googlemapszoomlevel(int zoomlevel) { 

was turned this:

public googlemapszoomlevel(@intrange(from=min_zoom_level, to=max_zoom_level) int zoomlevel) { 

now, right below line, doing safety checks in both versions of code:

if (zoomlevel < min_zoom_level || zoomlevel > max_zoom_level) {             throw new illegalargumentexception(error_zoom_level_out_of_bounds);         } 

question is, use support annotations keep these checks or not? reasoning behind keeping checks annotations temporary phenomena in particular ide , in event of working on code in ide, become unusable. also, recognizable , explicitly speak kinds of java developers backgrounds, unlike android studio-specific annotations.

technically, these checks unreachable in moment, because ide doesnt allow me use constructor, thinking it, if use code pass values constructor, instead of invoking hardcoded values, have no power over, , might wrong, these checks reachable, right?

am right, or should remove checks below annotated code?


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -