Hacker News new | past | comments | ask | show | jobs | submit login

Completely reasonable request, easy to implement along the lines of:

    public class Name {
        private Name(String name, int flag){...}
    
        public static Name asMissing(){new Name(null, -1);}
        public static Name asNotApplicable(){new Name(null, -2);}    
        public static Name asNotAvailableYet(){new Name(null, -3);}        
        public static Name asForbidden(){new Name(null, -4);}        
        public static Name create(String name){new Name(name, 0)}
        
        public boolean isMissing(){flag==-1}
        public boolean isNotApplicable(){flag==-2}
        public boolean isNotAvailableYet(){flag==-3}
        public boolean isForbidden(){flag==-4}
        public String get() {if (flag!=0) throw new Exception(flag) else name}
    }



Yep. I'd prefer enum-like syntactic sugar, something like:

   public class Name {
        private Name(String name){...}
    
        flags {
          MISSING, NOT_APPLICABLE, NOT_AVAILABLE_YET, FORBIDDEN
        }
        ...
    }
In particular, you shouldn't have to specify a constructor, since these are flag values that don't necessary have any state associated with them.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: