Using Boolean Object

I am having problems trying to get the result I want. Basically, what I want to do is to have a Boolean object that will allow me to have 3 options, if the mail program is old, I want it to be set to false (the value does not contain "mapQ.cmd" and "add- coid.cmd ")

if the mailer is new, I want it to be set to true (if it is new, it will contain the mapQ.cmd and add-coid.cmd files in the directory), and if it is not old or new mail (then there is no mailer), then I want it to be zero.

This is what I have, I want to put elseif instead of else and do another inside to set the value to zero, which means no higher, and then I want to return a boolean value. local-build-deploy.cmd is used in the example, but I want to use the above file names

private boolean isOldMailer(File mailerFolder) {
    File localBuildAndDeploy = new File(mailerFolder,"test/local-build-deploy.cmd");
    if (localBuildAndDeploy.exists()) {
        return true;
    } else {
        return false;
    }
}
+3
source share
4 answers

There are two ways to do this.

If you insist on using Boolean, use Capital B instead of lowercase b. Capital B Boolean is an object and can be set to null and do what you describe. The lowercase b boolean is primitive and cannot be set to null.

, 3 , 2.

, , , , . .

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;
}
+5

, . .

Boolean - , - true false.

, .

+1

( , ).

: true, false null. :

  • , , null, .
  • , null " " (.. , ), . .
  • .

, , , Boolean , , , .

: :

  • , null , ...
  • .
  • , , , .

- - <Boolean> Guava Google:

  • .
  • .
  • .
  • .
  • - .
  • / , .
+1

Boolean - . , null true false.

-1

Source: https://habr.com/ru/post/1769214/


All Articles