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.
精彩评论