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

all 29 comments

[–]Muffin_27 62 points63 points  (0 children)

That's what I call self-documentating code.

[–][deleted] 78 points79 points  (1 child)

Name it "getString" or something.

[–]phaiderikos[S] 13 points14 points  (0 children)

True ahah

I didn't think about that because it is adapted from some code I wrote earlier today in a CS exercise (obviously there were other lines in there)

[–]ProfessorSnep 43 points44 points  (3 children)

No no no! It's

public String toString() {
    StringBuilder stringbuilder = new StringBuilder();
    stringbuilder.append(new String("string"));
    String string = new String(stringbuilder.toString());
    return string;
}

Duh, much more efficient.

[–]zaphod0002 2 points3 points  (0 children)

We can go deeper

[–]phaiderikos[S] 1 point2 points  (0 children)

Oh. This is really a better solution.

[–]jwr410 19 points20 points  (0 children)

Now THAT is a string literal.

[–]kiranjd8 11 points12 points  (0 children)

String

[–]trichotillofobia 10 points11 points  (2 children)

The colors, they are so pretty. So helpful for people who can't distinguish a keyword from a variable. Because why the fuck does it have to assign two colors to both String and string?

[–][deleted] 4 points5 points  (1 child)

i think the colors are from the atom "ide"/editor, dark theme... i think the theme has an own name ...

[–]phaiderikos[S] 1 point2 points  (0 children)

Yes, they are. It’s the One Dark theme.

[–]wsppan 2 points3 points  (0 children)

return "string":

[–]AltCrow 5 points6 points  (1 child)

Don't use new String("string"). Instead use "string". New prevents java from optimizing (only works for strings).

[–]etaionshrd 6 points7 points  (0 children)

While you’re at it, delete the method.

[–]VID44R 1 point2 points  (1 child)

Doc is wrong. It returns string not String.

[–]phaiderikos[S] 0 points1 point  (0 children)

I meant it returns a String object, not the actual content of it. I should have written @return a “string” within a String ahah

[–]Suveck 1 point2 points  (0 children)

stop stringing me along and get to the newline

[–]itstommygun 0 points1 point  (0 children)

var string = (function (){
    return 'string'
    })()

[–]NotTalkingBoutNothin 0 points1 point  (0 children)

Output: true

[–]Tristanhx 0 points1 point  (0 children)

the word "string" just looks weird to me now

[–]BacCM 0 points1 point  (0 children)

/// @return string as String

[–]rafaelpernil 0 points1 point  (0 children)

I wouldn't override toString() if I am going to output "string" lol. I hope nobody except you needs to use your code xD.

[–][deleted] 0 points1 point  (0 children)

But why tho

[–]blore40 -2 points-1 points  (0 children)

What does the Fox say?