Java – use Boolean objects
I had a problem trying to get the results I wanted Basically, what I want to do is have a Boolean object, which will allow me to have three choices. If the mail program is old, I want it to be set to false (meaning that it does not contain "mapq. CMD" and "add coid. CMD" files)
If the mail program is new, I want it to be set to true (if it is new, it will include "mapq. CMD" and "add coid. CMD" files in the directory). If it is neither old mail program nor new mail program (meaning not mail), then I want it to be empty
This is what I have. I want to put an else if instead of else, and set a null value in it, which means the above non, and then I want to return a Boolean value local-build-deploy. CMD is used in the example, but I want to use the file name above
private boolean isOldMailer(File mailerFolder) { File localBuildAndDeploy = new File(mailerFolder,"test/local-build-deploy.cmd"); if (localBuildAndDeploy.exists()) { return true; } else { return false; } }
Solution
There are two ways to do this
If you insist on using Boolean values, use upper case B instead of lower case B. capital B Boolean is an object that can be set to null and perform the operations you describe Lowercase B Boolean values are primitives and cannot be set to null
However, when designed as 2, there is a better way not to rely on Boolean values for three values
Using enumeration, you can define types as needed and provide as many types as needed This is an example and how to use it
public enum Status { NEW,OLD,NEITHER } private Status isOldMailer(File mailerFolder) { File localBuildAndDeploy = new File(mailerFolder,"test/local-build-deploy.cmd"); if (localBuildAndDeploy.exists()) return Status.NEW; else if (/*Something else*/) return Status.OLD else return Status.NEITHER; }