r/programminghumor • • 1d ago

Java

Post image
964 Upvotes

21 comments sorted by

97

u/y0shii3 1d ago

How you do it
vs how your teacher does it
vs how your classmate does it
vs how Spring devs do it

1

u/Zealousideal_Joke552 2h ago

Meanwhile C++ madmen that refuse to use a library or framework and make everything from scratch

63

u/Ignisami 1d ago edited 1d ago

You're missing

if (Boolean.TRUE.equals(condition)) which is what SonarQube's default Java rules will recommend. (edit: in case anyone wonders, it's because of null safety; if (condition) throws an NPE if condition is null, Boolean.TRUE.equals(condition) just evaluates to false)

35

u/NoWeHaveYesBananas 1d ago

What if you want it to throw an error, and not hide your bugs like a coward

18

u/vanteli 1d ago

you tighten your pussy like a man and assert condition != null;

15

u/Ignisami 1d ago
try {
if (condition) { /* code whatever */ }
} catch (MommaAintRaisedNoCowardException _) {
log.error("No bugs to be seen here no sirreee");
}

public class MommaAintRaisedNoCowardException  
 extends NullPointerException   
{ /* standard exception stuff */ }

19

u/yousirnaime 1d ago

if( LlmService.request(" does this seem truthy, respond only 'yes' or 'no' : " . condition) == '{"response":{"message":"yes"}}'){

}

10

u/Simple-Olive895 1d ago

if (myBool == true) {

return true

}

2

u/xaranetic 21h ago
package check.true;

public class TrueCheck {

    public enum Truth {
        TRUE;

        public boolean asPrimitiveBoolean() {
            return Boolean.parseBoolean(this.name().toLowerCase());
        }
    }

    public static class True {
        private final Truth truth;

        private True(Truth truth) {
            this.truth = truth;
        }

        public static True getTrue() {
            return new True(Truth.TRUE);
        }

        public boolean value() {
            return this.truth.asPrimitiveBoolean();
        }
    }

    public boolean checkIfTrue(boolean myBool) {
        if (myBool == true) {
            return True.getTrue().value();
        }
        return !True.getTrue().value();
    }
}

11

u/Varderal 1d ago

Reminds me of one time in a class. I needed to get from one datatype to another with no clear way... I kinda did "variable.toThis.toThat.toAnother.toTarget". Asked rhe teacher if there was an easier way and he just looked at it and went "the fuck is that?" I was all "exactly!" XD

1

u/realmauer01 1d ago

Sometimes that happens in java, you have to transform stuff to a stream that stream to an array and then you can do stuff like for each or map.

4

u/Forward_Republic_610 1d ago

I am missing the hangman in the last picture.

4

u/Dinatoc_208 1d ago

when you're paid per line of code

2

u/CjMori23 1d ago

This is what the twitter devs that didn’t get fired were writing

1

u/NoodlyGirl2000 1d ago

I do have a lot of fond memories of Java, but I also think C# does it so much better

1

u/induality 1d ago edited 1d ago

The fourth one isn’t even correct. The comparator compare method returns an int. You need to check that that return value equals zero.

1

u/tatstytastycakes 1d ago

class vs homework vs quiz vs exam

1

u/DONARUDO_TURANPU 1d ago

Doesn't Java have some ternary operator like JS? That would be the first image but in full HD 3D

1

u/Zezerok 1d ago

I do most time 1 and sometimes 2 for the readability

1

u/AndromedaGalaxy29 1d ago

second one is good for readability sometimes 

0

u/ThePhyseter 1d ago

Guy #3 came from Javascript and never learned about == vs ===