Reputation: 6645
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 set to any other value except start or data or end ??
Upvotes: 0
Views: 811
Reputation: 48121
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.
Upvotes: 3