Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31103

Re: "null", polymorphism and TCO

From Kevin McMurtrie <mcmurtrie@pixelmemory.us>
Newsgroups comp.lang.java.programmer
Subject Re: "null", polymorphism and TCO
References <null-20150208185452@ram.dialup.fu-berlin.de> <mcmurtrie-19F4EE.23064308022015@news.sonic.net> <mba2ip$3nr$1@gwaiyur.mb-net.net>
Date 2015-02-09 20:35 -0800
Message-ID <mcmurtrie-338D50.20354409022015@news.sonic.net> (permalink)
Organization Sonic.Net

Show all headers | View raw


In article <mba2ip$3nr$1@gwaiyur.mb-net.net>,
 Marcel Mueller <news.5.maazl@spamgourmet.org> wrote:

> On 09.02.15 08.06, Kevin McMurtrie wrote:
> > If Oracle ever optimizes away the String(String) constructor it's going
> > to break a lot of code where I have to terminate String queues with
> > something like this:
> >
> > static final String endOfQueue= new String("end");
> >
> >   ...
> >
> > while ((item= queue.take()) != endOfQueue)
> > {
> >   ...
> > }
> > queue.put(endOfQueue);
> 
> The reference equality trick (instead of null) will work with /any/ 
> other object as well. There is no need for String(String).
> 
> 
> Marcel

An enum named something like EOF is, of course, much better but it can't 
be put into BlockingDeque<String>.

Every once in a while I hear talk of adding automatic String interning 
or optimizing away the String(String) constructor such that this becomes 
true:
new String("foo") == "foo"

It would surely break tons of code.  Not only would it break unique 
tokens, but it would break WeakHashMap<String, ?> too.

-- 
I will not see posts from astraweb, theremailer, dizum, or google
because they host Usenet flooders.

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: "null", polymorphism and TCO Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2015-02-08 23:06 -0800
  Re: "null", polymorphism and TCO Marcel Mueller <news.5.maazl@spamgourmet.org> - 2015-02-09 11:36 +0100
    Re: "null", polymorphism and TCO Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2015-02-09 20:35 -0800
      Re: "null", polymorphism and TCO Marcel Mueller <news.5.maazl@spamgourmet.org> - 2015-02-10 10:37 +0100
        Re: "null", polymorphism and TCO Joshua Cranmer 🐧 <Pidgeot18@verizon.invalid> - 2015-02-10 12:51 -0600

csiph-web