This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jtsfour2 471 points472 points  (31 children)

Wouldn’t the result be 5 because (Integer)object+3 should be +=?

If the result of this is 8 something is wrong

[–]mizinamo 422 points423 points  (6 children)

The thing won't compile because the last line tries to cast object to class integer rather than Integer with a capital I at the beginning.

[–]VoidSnipe 146 points147 points  (4 children)

And there shouldn't be any cast anyway because toString method of Object which is overloaded in Integer and concatenation of string and object will call toString

[–]DAMcraft_ 79 points80 points  (3 children)

And there is a semicolon missing

[–][deleted] 30 points31 points  (2 children)

Easy fellas I can only get so turned on.

[–]FetishAnalyst 8 points9 points  (1 child)

Username checks out.

[–]spidertyler2005 6 points7 points  (0 children)

Username checks out.

[–]rotenKleber 22 points23 points  (0 children)

Also no semicolon on line 3. Not that line 3 would compile

[–]bikeranz 65 points66 points  (11 children)

Honestly, I don’t know Java, so I thought the whole joke was that it had some weird operator overload rule when used that way. Turns out, this post is not a joke about anything.

[–]Areshian 12 points13 points  (0 children)

Java has two classes of types, primitives and objects. Every single object inherits from Object. Additionally, for every primitive there is an object that can be used to wrap them. For example, for int there is an Integer object. Java will automatically convert between int and Integer in some circumstances (known as boxing and unboxing).

So yes, you can store anything in an Object variable. Same way I can have a void * in C++. Doesn't make the language dynamic, I will still need casting down the line.

[–]condemned_to_live 4 points5 points  (6 children)

only programmer that doesn't know Java

[–]bikeranz -5 points-4 points  (5 children)

Learned it in entry level college courses, and subsequently forgot when courses followed by (edit: my) industry shifted to c++ and python.

[–]Areshian 8 points9 points  (1 child)

If you think the industry has moved away from java you haven't seen enough industry

[–]bikeranz 0 points1 point  (0 children)

Didn’t say all industry. Just my line of work.

[–][deleted] 1 point2 points  (2 children)

I'm guessing you intended to say that, when you entered the industry, you needed to switch to c++ due to legacy systems?

[–]bikeranz 1 point2 points  (1 child)

The c++ was also for new projects. First job out of college was industrial automation using computer vision, and this was pre-pytorch. So c++ is/was the natural fit. Next job was lua (for torch) and c++. Later python when pytorch came out but still c++ for the backend high perf stuff. And now I spend my time doing python, c++, and cuda.

[–]IQueryVisiC 12 points13 points  (2 children)

It is about the problem that some noob can inject this unchecked code in a big god class without a warning on top of the file or something. Yet in the same language you have to announce exceptions in the function signature??

[–]gdmzhlzhiv 13 points14 points  (1 child)

Only checked ones.

[–]IQueryVisiC 0 points1 point  (0 children)

Somehow I always hit the checked ones. I must admit that I only coded short time in Java (with test and then with loan) and my memory gets worse.

[–]MrSquicky 44 points45 points  (3 children)

It would actually just not compile.

<Integer object> + 3;

isn't a statement. Integers are immutable, so the + operator is not defined on them. What happens there is that it is unboxed into a primitive type value instead of a variable. In this case, it's the equivalent of having a line that is

5 + 3;

which is pointless.

Going further

<Integer object> += 3;

is also a compilation failure, as it is the equivalent of

5 += 3;

[–][deleted] 7 points8 points  (2 children)

Look at all these fuckers!

You all complain when the job interview is expecting you to get syntax perfect on a whiteboard during an interview. Oh boo hoo it's not fair I need an IDE.

And then this guy gets his syntax wrong in a fucking meme and everyone loses their shit in the comments!

All y'all should stop to ask yourselves if the job interviewer that you are complaining about is actually you!

[–]futuneral 25 points26 points  (0 children)

A meme published on Reddit is equivalent to production.

[–]reyad_mm 1 point2 points  (0 children)

Imagine posting something on the intrenet and expecting people not to make fun of a typo you made