Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31633
| 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 | 2015-04-30 11:32 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <mhths3$c00$1@dont-email.me> (permalink) |
| References | <3eceaed0-2cfa-4fac-89d6-23445a670f84@googlegroups.com> |
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