• Post Reply Bookmark Topic Watch Topic
  • New Topic

Range of variable  RSS feed

 
Ray Anderson
Ranch Hand
Posts: 98
Java Oracle Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

is there any way to set the range of a variable ?
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you elaborate?
What type of variable?
I think there is no in-built mechanism in Java to handle this for any type of variable.
 
Ray Anderson
Ranch Hand
Posts: 98
Java Oracle Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example,
take int hour, if there is a possibility to set the range from 0 to 23 ?
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there is no in-built mechanism for setting a range from 0 to 23. It has to be done manually.
I can think of several ways to do this.
1. Define the validation logic in constructor.
2. Define the validation logic in setter.
3. Create a new class, say, MyHour and define the logic there.
 
Ray Anderson
Ranch Hand
Posts: 98
Java Oracle Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thanks for helping.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!