开发者

restricting values for a string member variable

A string variable in Java can take one of the three values type=start, type=data, type=end .. what would be the best way to make sure it never gets s开发者_开发知识库et to any other value except start or data or end ??


Consider using an Enum instead of a String.

Failing that, make it a private member and use a setter method that validates the value. Of course, this won't protect you against code within the class itself directly setting the value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜