A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Java in General
Author
Overloading with Varargs
sr shashidhar
Greenhorn
Joined: Jan 17, 2013
Posts: 21
posted
Jan 29, 2013 06:28:53
0
Hi frndz
class A { static void m1(int...x) {System.out.println("INTEGER");} static void m1(byte...y) {System.out.println("BYTE");} } class B { public static void main(String[] args) { byte b1=3; byte b2=7; A.m1(b1,b2); }}
While compiling getting exception as
Exception in thread "main"
java.lang.Error
: Unresolved compilation problem:
The method m1(int[]) is ambiguous for the type A
my doubt is according to overloading concept Output must be "BYTE", but why Compilation error..
Thanks in advance
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
I like...
posted
Jan 29, 2013 07:39:17
0
Which compiler are you using? If I compile that code with Java 7u11 I get no errors at all, and it also runs just fine, printing BYTE.
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions
How To Answer Questions
sr shashidhar
Greenhorn
Joined: Jan 17, 2013
Posts: 21
posted
Jan 29, 2013 08:46:48
0
J2SE 5.0(1.5)
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4747
7
I like...
posted
Jan 29, 2013 08:52:15
0
sr shashidhar wrote:
J2SE 5.0(1.5)
Erm...you do understand that J2SE 5.0 entered its end-of-life on April 8, 2008 and hasn't been supported by Sun/Oracle since November 3, 2009?
That's quite apart from any questions about why you're overloading methods with ellipses...
Winston
Isn't it funny how there's always time and money enough to do it WRONG?
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Overloading with Varargs
Similar Threads
casting
casting
data type
Understanding Byte and == Op
Primitive variable assignments
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter