Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31633
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: If java doesn't support operator overloading, how does String + concatenation work |
| Date | Thu, 30 Apr 2015 11:32:14 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 33 |
| Message-ID | <mhths3$c00$1@dont-email.me> (permalink) |
| References | <3eceaed0-2cfa-4fac-89d6-23445a670f84@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Thu, 30 Apr 2015 15:31:15 +0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="858a9d65d95f4ea4d355bd116aa2cdbf"; logging-data="12288"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xOKmjqPufBGBt1KesCA4U" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
| In-Reply-To | <3eceaed0-2cfa-4fac-89d6-23445a670f84@googlegroups.com> |
| Cancel-Lock | sha1:rPpbY523C+ItkOIOImiaQEjUAIY= |
| Xref | csiph.com comp.lang.java.programmer:31633 |
Show key headers only | View raw
On 4/30/2015 10:10 AM, Ajay Paul wrote:
> I understand that java doesn't support operator overloading. If so, how does String + concatenation work ?
Java *does* support operator overloading. You've noted that `+' can
concatenate two Strings; it can also add two doubles, or two floats, or
two longs, or two ints. Similarly, `<' can compare doubles, floats,
longs, ints, shorts, chars, or bytes. `==' and `!=' can compare all
those, and can compare references also.
However, Java does not support programmer-defined overloads: Its
operators and their overloads are built in to the language, and cannot
be extended by writing Java code. (In a trivial sense, defining a new
class or interface extends the `==' and `!=' and `?:' operators to
apply to new reference types -- but that's a pretty weak "overload.")
A useful way to think about this is to separate the notion of an
operator from the particular source symbol that represents it. We
may then say that the source symbol `+' can represent any of five
different operators, depending on context:
String concatenation
double addition
float addition
long addition
int addition
(Note that although `+' can be used with short and char and byte as
well, these types are widened to int before the operator operates,
so there's really no "short addition" operator.)
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
If java doesn't support operator overloading, how does String + concatenation work Ajay Paul <ajaykpaul@gmail.com> - 2015-04-30 07:10 -0700
Re: If java doesn't support operator overloading, how does String + concatenation work Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-04-30 11:32 -0400
Re: If java doesn't support operator overloading, how does String + concatenation work Robert Klemme <shortcutter@googlemail.com> - 2015-04-30 23:46 +0200
Re: If java doesn't support operator overloading, how does String + concatenation work v_borchert@despammed.com (Volker Borchert) - 2015-05-01 06:33 +0000
csiph-web