Check if function returns true

Discussion in 'Plugin Development' started by Meatiex, Aug 7, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Meatiex

    This is sort of a noob question, but how would I check if a Boolean function returns true with a if statement?
    Code:java
    1. public static boolean allow(String cmd) {
    2. if (!cmd.startsWith("mail")) {
    3. return true;
    4. }
    5. return false;
    6. }

    Any help is awesome, Thanks :D
     
  2. Offline

    teej107

    Meatiex This is basic Java and I hope you continue to further your learning.
    Code:java
    1. if(yourMethod())
    2. {
    3. }
     
  3. Offline

    Meatiex

    Thanks :D
    Heres what I gathered and it works :D
    Code:java
    1. GlobalFilter.allow(command);
    2. if (true) {
    3.  
    4. }
     
  4. Offline

    Double0negative

    Uh, please go learn some basic programming concepts.

    Testing of something is true by testing 'true' is always going to be true meaning it is pointless to test it
     
    chasechocolate and Gerov like this.
  5. Offline

    teej107

    Meatiex Of coarse it will work. Your if statement will always return true therefore making the code inside execute every time. Doing that is not needed. The whole point of an if test is so that you can control if the code should run. In your case, there is no control since it will always be true. You did not correctly follow my example.
     
Thread Status:
Not open for further replies.

Share This Page