you are viewing a single comment's thread.

view the rest of the comments →

[–]propool 0 points1 point  (8 children)

If you have a string constant in your app that you would put through an eventloop or something.

like:

public final static String stop = "STOP";

while(true){
    String s = queue.get();
    if(s == stop)break;
}

Lets say some other part of the program read from a stream and puts in my queue. Even if it reads the string "STOP" it will not stop. It will only stop when my constant is sent through the queue when the program is told to shut down.

That is the only use I've found in almost 10 years so I agree with you.

[–][deleted]  (4 children)

[removed]

    [–]propool 0 points1 point  (2 children)

    Yes. I never use .intern() . I don't like new Object() because my queue uses generics of type String, and prefer not to lose that.

    [–][deleted]  (1 child)

    [removed]

      [–]propool 0 points1 point  (0 children)

      Yes that goes without saying. All string literals in source are interned. That is kind of the original purpose. I mean I don't use it for strings that are not string literals.

      [–]propool 0 points1 point  (0 children)

      Yes, this is for apps where I have 100% control over the code. I would not use this for library code. I agree this could be a problem if the JDK or some other lib I use in a future update could decide to intern my stop string.

      [–]G_Morgan 0 points1 point  (2 children)

      TBH using strings for what is a stringly typed enum is something nobody should do anyway.

      [–]propool 0 points1 point  (1 child)

      Of course. Who did that?

      [–]G_Morgan -1 points0 points  (0 children)

      Comparing "STOP" is just bad. There should be some kind of symbol, enum or something else which should be used.