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


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

Re: What does keyword 'this' refer to in the following code?

Path csiph.com!weretis.net!feeder4.news.weretis.net!news.albasani.net!.POSTED!not-for-mail
From Lars Enderin <lars.enderin@telia.com>
Newsgroups comp.lang.java.programmer
Subject Re: What does keyword 'this' refer to in the following code?
Date Wed, 13 Apr 2016 10:58:06 +0200
Organization albasani.net
Lines 29
Message-ID <570E0A1E.6070608@telia.com> (permalink)
References <2a655d5f-3df0-4bf2-a2bc-4b70406d7ab2@googlegroups.com> <nejr5l$8c9$1@dont-email.me> <0ecdea31-577e-4117-b6f0-c0a9d42bf3f3@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net iT/8kql8d5S/rDL6TzFdlsGBlT8fcQdJfhOsQpPUwxNlqqEgxFpVNvEu4hmEdJpXD5ExNhPP2LcHn3uriC3iOujBHFCnDUiW05A/vw/PcjEifMrjiDHeQU/DYFjZuXEu
NNTP-Posting-Date Wed, 13 Apr 2016 08:58:06 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="qrkR2U+2VguCu07Odo0gPjM261xj4ZqWIP6CO3MrDt3JU+jNoJfAjBraxcm9+pzArMpdDU0TthNcPDgzX6nwh/4iOX2Pq/C87qeKGPKUN272aXxzZKwb1j1b3pjNZBK3"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0
In-Reply-To <0ecdea31-577e-4117-b6f0-c0a9d42bf3f3@googlegroups.com>
Cancel-Lock sha1:YYbKZJ9TkwmtwyKxw+LXOMBFf/8=
Xref csiph.com comp.lang.java.programmer:34120

Show key headers only | View raw


2016-04-13 05:03 skrev  cdalten@gmail.com:
> I have another question. What's the significance of map.addMarker().title().snippet().position()?
> 
> Why not just do something like
> map.addMarker()
> map.title()
> map.snippet()
> map.position()
> ?

It's a shorthand, assuming that each method in the chain returns *this*.
If you look at the source for java.lang.StringBuilder, for example,
you'll find methods like

    public StringBuilder append(int i) {
        IntegralToString.appendInt(this, i);
        return this;
    }
and
    public StringBuilder append(double d) {
        RealToString.getInstance().appendDouble(this, d);
        return this;
    }

so you can write statements like
StringBuilder sb = new StringBuilder().append("Pi = ").append(Math.PI);

-- 
Lars Enderin

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


Thread

What does keyword 'this' refer to in the following code? cdalten@gmail.com - 2016-04-11 21:44 -0700
  Re: What does keyword 'this' refer to in the following code? Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2016-04-12 12:16 +0300
  Re: What does keyword 'this' refer to in the following code? Eric Douglas <e.d.programmer@gmail.com> - 2016-04-12 04:57 -0700
    Re: What does keyword 'this' refer to in the following code? cdalten@gmail.com - 2016-04-12 08:28 -0700
      Re: What does keyword 'this' refer to in the following code? Lew <lewbloch@gmail.com> - 2016-04-12 14:03 -0700
        Re: What does keyword 'this' refer to in the following code? cdalten@gmail.com - 2016-04-12 18:23 -0700
          Re: What does keyword 'this' refer to in the following code? Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2016-04-13 11:39 +0300
          Re: What does keyword 'this' refer to in the following code? Eric Douglas <e.d.programmer@gmail.com> - 2016-04-13 05:07 -0700
  Re: What does keyword 'this' refer to in the following code? Jeff Higgins <jeff@invalid.invalid> - 2016-04-12 22:00 +0000
    Re: What does keyword 'this' refer to in the following code? cdalten@gmail.com - 2016-04-12 20:03 -0700
      Re: What does keyword 'this' refer to in the following code? cdalten@gmail.com - 2016-04-12 21:01 -0700
      Re: What does keyword 'this' refer to in the following code? Lars Enderin <lars.enderin@telia.com> - 2016-04-13 10:58 +0200
      Re: What does keyword 'this' refer to in the following code? Eric Douglas <e.d.programmer@gmail.com> - 2016-04-13 05:12 -0700

csiph-web