Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

overloaded error

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


This code is thrown an exception:


C:\deploy\pbnm\class\src\GFC213.java:36: reference to m is ambiguous, both method m(GFC211,GFC212) in GFC213 and method m(GFC212,GFC211) in GFC213 match
GFC213 gfc213=new GFC213();m(gfc213,gfc213);
1 error
BUILD FAILED (total time: 0 seconds)


methods are properly overloaded ,why it has thrown error ?

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


methods are properly overloaded ,why it has thrown error ?



It is not because you have overloaded methods properly; It is due to
method call that is ambiguous. Compiler does not find more specific method
than other to satisfy your method call.


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

you are passing gfc213,gfc213 as argument to m() method.

static void m(GFC212 x,GFC212 y) {System.out.println"GFC211 ,GFC211"); }
static void m(GFC211 x,GFC213 y) {System.out.println("GFC211 ,GFC211"); }

every call which m(GFC212 x,GFC212 y) can take m(GFC211 x,GFC213 y) also can be take except if first argument is reference variable of GFC211 type that can not be handled by m(GFC212 x,GFC212 y) but in our case parameters compiler will not be able to choose the most specific type as we are passing GFC213 type as parameter which can be handled by both the method.
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi kumarth,

have a look at the following dicussion.

[Edit] URL corrected.
[ June 29, 2007: Message edited by: Manfred Klug ]
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic