File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Use of boolean flags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Use of boolean flags" Watch "Use of boolean flags" New topic

Use of boolean flags

Gail Mikels
Ranch Hand

Joined: May 07, 2001
Posts: 634
In the app I'm working on, we have a table class that displays data. The user can load and reload data at various times, calling the table's load() method. I need to do one bit of logic ONLY on the first time load() is called. I'm considering using a boolean flag so I can check whether or not it's the first. But I seem to recall a fellow programmer or two turning their nose up at using flags in general....

Any opinions out there?

Gail Mikels
mohsen fakhari

Joined: May 04, 2003
Posts: 25
if you don't have something that shows you the state itself,I think you don't have any way else
but don't let the flag to be global if you can.
Dana Bothner-By
Ranch Hand

Joined: Jul 28, 2006
Posts: 37
A "flag" is just a boolean field, right? So what's to cock a snoot at?
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
as mentioned above: if you can not check the state then you have to add a "flag".
perhaps you can "abuse" a different field ?

if they keep their noses up.... just call it "state" instead of flag, make it an int and assign it another value after each "phase" (e.g. init, load, reload, delete, flush or wahtever you have) :-)

Gail Mikels
Ranch Hand

Joined: May 07, 2001
Posts: 634
Ok - Thanks for your support, guys. I'm gonna go ahead & use the flag. I tried "abusing" an existing field, but it didn't work out. I think these people "learned" something about a particular situation where maybe using the flag was bad, & are trying to over-apply it.

Thank you for all the input - you guys rock!
I agree. Here's the link:
subject: Use of boolean flags
It's not a secret anymore!