• 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

Reg. casting in method calls

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below is a question from Barry Boone's exam :

I am not clear as to how the "long" will be
converted to "double"
Is implicit casting allowed in method calls.
i.e conversion as below from left to right are done automatically

I was under the impression that only byte,short , char
if found will be implicitly converted to int
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi angela,
it is right that long can be converted into double or float between method calls. As u have double as the first param in the method call so u only have two options:
void test(double a, double b, short c) //1
void test(double a, double b, double c) //2
out of which u have to select, as the last param of method is 3 i.e. of type int so the first one wouldn't be called though 3 falls within the range of short. NOw in //2 both long and int can be converted to double. Hence, //2 would be invoked.
HIH,
ashok.

Originally posted by Angela Narain:
[B]Below is a question from Barry Boone's exam :

I am not clear as to how the "long" will be
converted to "double"
Is implicit casting allowed in method calls.
i.e conversion as below from left to right are done automatically

I was under the impression that only byte,short , char
if found will be implicitly converted to int[/B]


 
Angela Narain
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ashok.
So does it mean that as shown in my post, the implicit
casting works for primitive dataTypes.
But the same does not work it the parameters are arrays
For eg: int[] arr in actual parameter call cannot
call a method with long[] arr as parameter
Pls. correct me if wrong .
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ashok ,implicit casting from int to short works
(e.g short s = 3 but the same does not work for method calls
in the example of Angela.
Is there any rules regarding this .
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Angela you are right.
Monzy:
In the JLS Chapter 5 deals with conversions. A method invocation context allows several kinds of conversions: identity and widenning but no the implicit primitive narrowing conversion allowed in the assignment conversion.
 
Police line, do not cross. Well, this tiny ad can go through:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic