Win a copy of Rust Web Development this week in the Other Languages 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic