Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39622
| From | Wayne <wayne@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java Overloading rules confusion |
| Date | 2020-10-09 22:51 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <rlr7jo$qcg$2@dont-email.me> (permalink) |
| References | <rloivp$k46$1@dont-email.me> <rlpo5m$91o$1@dont-email.me> |
On 10/9/2020 9:21 AM, Eric Sosman wrote:
> On 10/8/2020 10:47 PM, Wayne wrote:
>> I have a question on overloading in Java. [...]
>>
>> Shouldn't "m(int,float)" be more specific than "m(double,int)"?
>
> Had to spend some time studying JLS 15.12.2.5 to find that the
> answer is "No." There's a lot if niggly detail in the JLS, but for
> me the easiest explanation comes in the introductory section:
>
> "The informal intuition is that one method is more specific
> than another if any invocation handled by the first method
> could be passed on to the other one without a compile-time
> error."
>
> Let's try this out with your two versions of m(). Clearly, both
> versions could (in isolation) handle m(3,4) or m('3',4) and many
> other invocations. However, m(3,4.0f) would work only with the
> (int,float) version, but only (double,int) could handle m(3.0,4).
> That is, for each version there is an invocation that it could
> accept but would not work with the other. So (says "informal
> intuition") neither is "more specific" than the other, because
> each has valid invocations the other could not accept.
>
> Interesting query. Thanks!
>
I appreciate your reply, it does help. Thanks!
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Java Overloading rules confusion Wayne <wayne@nospam.invalid> - 2020-10-08 22:47 -0400
Re: Java Overloading rules confusion Marcel Mueller <news.5.maazl@spamgourmet.org> - 2020-10-09 09:01 +0200
Re: Java Overloading rules confusion Eric Sosman <esosman@comcast-dot-net.invalid> - 2020-10-09 09:21 -0400
Re: Java Overloading rules confusion Wayne <wayne@nospam.invalid> - 2020-10-09 22:51 -0400
Re: Java Overloading rules confusion Arne Vajhøj <arne@vajhoej.dk> - 2020-10-09 09:59 -0400
Re: Java Overloading rules confusion Wayne <wayne@nospam.invalid> - 2020-10-09 22:51 -0400
csiph-web