This week's book giveaway is in the Kotlin forum.We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

kirba devi
Ranch Hand
Posts: 50
class Dog3 {
static void go(long x) { System.out.print("int "); }
static void go(int x) { System.out.print("double "); }
static void go(double...x) { System.out.print("double "); }
public static void main(String[] args) {
Dog3 d = new Dog3();
double b = 5;
double s = 5;
int l = 5;
float f = 5.0f;
go(b);
go(s);
go(l);
go(f);
}
}

output ouble double double double .How?
my expected output ouble double int double
As per my knowledge,
1)first matching occurs by the use of primitives,it can be widening in some cases.
2)then boxing
3)then var-args

Regards
Kirba

Plase correct me if iam wrong.

Henry Wong
author
Sheriff
Posts: 23283
125

Maybe this has something to do with... your int version of the method, also prints double.

Henry

kirba devi
Ranch Hand
Posts: 50
Hi Wong,
Thanks for identifying the problem.
2)We can box and widen..//for this can you explain with example.
3)We cannot widen from one wrapper type to another

eg ublic static void go(Long x) {}

Integer x=5;
go(5);
Above example is what rule 3 says? Please correct if iam wrong!!!

4)We cannot widen and box:
eg ublic static void go(Long x) {}

int x=5;
go(5);

Regards
Kirba.

Deepak Bala
Bartender
Posts: 6663
5
What is the source of this question ?

kirba devi
Ranch Hand
Posts: 50
From K&B book

chpater-3 -Assignment Page NO:244

Regards
Kirba