• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Varargs overriding

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see the following piece of code:

Output:

1. (String) => (String, Number[]) // why not (String, Integer[]) or (String, Object[])
2. (String, int) => (String, Number[]) // why not(String, Integer[])
3. (String, Integer) => (String, Number[]) // why not(String, Integer[])
5. (String, int, int) => (String, Number[]) // why not(String, Integer[])
7. (String, int, int, int) => (String, Number[]) // why not(String, Integer[])

My questions are in comments above.

Thanks
[ February 05, 2006: Message edited by: Mark Spritzler ]
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's strange. When I compiled and ran the code This was my output:

I wonder why the two different outputs?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't compile for me because public int doIt(String str, Integer... data) is not implemented in the sub class.

If I replace
public int doIt(String str, Integer[] data)
with
public int doIt(String str, Integer... data)
, I'll get the same as Garrett

Overridden: 1. (String) => (String, Integer[])
Overridden: 2. (String, int) => (String, Integer[])
Overridden: 3. (String, Integer) => (String, Integer[])
Overridden: 5. (String, int, int) => (String, Integer[])
Overridden: 7. (String, int, int, int) => (String, Integer[])
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
It doesn't compile for me because public int doIt(String str, Integer... data) is not implemented in the sub class.


I got a warning about that but the program still compiled.
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,

with 1.5.0 and with 1.5.0_04 I got what Garret got, although these compiler versions behave differently in related aspects. What compiler and jvm did you use, Krishna?

Combining autoboxing and overloading is a dangerous mixture. The compiler behaviour has been changed a lot regarding this, even after the final release of 1.5.0 on September 30th, 2005. It would be very unfair to ask questions about this in the SCJP 5.0 test. I know huge frameworks that had already been published which were written for the final 1.5.0 and which became hardly usable in 1.5.0_01 or 1.5.0_02.

Kai
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using 1.5.0_06 and got the compile error.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic