Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39615
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Wayne <wayne@nospam.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Java Overloading rules confusion |
| Date | Thu, 8 Oct 2020 22:47:19 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 42 |
| Message-ID | <rloivp$k46$1@dont-email.me> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Fri, 9 Oct 2020 02:47:21 -0000 (UTC) |
| Injection-Info | reader02.eternal-september.org; posting-host="df9d9c0d2abbc6894623549e5a18259b"; logging-data="20614"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/aXP9WEb4mJvyEpnIkhIA0Pwc57oMEUHQ=" |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.3.2 |
| Cancel-Lock | sha1:JlFxK2bxVhVoi1VQRBaO4AeVp6Q= |
| Content-Language | en-US |
| X-Mozilla-News-Host | news://news.eternal-september.org:119 |
| Xref | csiph.com comp.lang.java.programmer:39615 |
Show key headers only | View raw
I have a question on overloading in Java. I find the language
specifications confusing on this issue.
Why will this:
class Foo {
public static void main ( String[] args ) {
m(3, 4);
}
static void m (double d1, int i2) {
System.out.println( "m(d,i)" );
}
static void m (float f1, int i2) {
System.out.println( "m(f,i)" );
}
}
Compile and run, producing "m(f,i)", but this:
class Foo {
public static void main ( String[] args ) {
m(3, 4);
}
static void m (double d1, int i2) {
System.out.println( "m(d,i)" );
}
static void m (int i1, float f2) {
System.out.println( "m(i,f)" );
}
}
does not compile and gives this error:
Foo.java:3: error: reference to m is ambiguous
m(3, 4);
^
both method m(double,int) in Foo and method m(int,float) in Foo match
Shouldn't "m(int,float)" be more specific than "m(double,int)"?
(This works IF you change the first m(double,int) to m(int,double).)
--
Wayne
Back to comp.lang.java.programmer | Previous | Next — 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