• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

method is ambiguous

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



1. public class Test2 extends Test {

2.public static void main(String args[]) {
3.Test2 obj = new Test2();
4.final byte b = 10;
6.obj.name(b);
7.}

public static void name(short c) {
System.out.println(" short type from subclass.."+c);
}
}




public class Test {

public static void name(short c) {
System.out.println(" short type from superclass.."+c);
}
public static void name(byte c) {
System.out.println(" byte type from superclass.."+c);
}


}



The code at line number "6" "obj.name(b)" is giving error

ERROR:
The method name(short) is ambiguous for the type Test2

Why does the compiler considers widening conversion of byte to short in method invocation if there is a method in Superclass which can accept the byte as parameter?

if i remove "public static void name(short c) " from Subclass Test2, then it compiles correctly.
[ November 21, 2007: Message edited by: gurpreet singh ]
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!
that code compiles correctly on my machine.
 
gurpreet singh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have edited the post. Can you please check it now?

I am using jdk1.4

[ November 21, 2007: Message edited by: gurpreet singh ]
[ November 21, 2007: Message edited by: gurpreet singh ]
 
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by gurpreet singh:
I have edited the post. Can you please check it now?

I am using jdk1.4



This shouldn't cause a compile error. Are you using Eclipse? From a cursory Google search, it seems that there was a bug in one of their earlier JDT versions that caused extraneous "method is ambiguous" errors.
 
gurpreet singh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kelvin

You are right. Its the bug in eclipse.
 
reply
    Bookmark Topic Watch Topic
  • New Topic