Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Question about Autoboxing in Method paramaters

 
Greenhorn
Posts: 13
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I am currently reading Jeanne Boyarsky's OCA SE8 book and I just have a quick question about auto boxing in method parameters. So, at the bottom of page 195 to the top of page 196, there is an example that shows that play(4) can not compile because it "cannot handle converting in two steps to a long and then to a Long". I'm kind of confused by this because it says that it will be happy to convert the int 4 to a long or an Integer. So if it can convert it to an Integer, why can't it convert it to a Long?

Here is the code:


                   
 
author
Posts: 23878
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Alexander Caleb wrote:So, at the bottom of page 195 to the top of page 196, there is an example that shows that play(4) can not compile because it "cannot handle converting in two steps to a long and then to a Long". I'm kind of confused by this because it says that it will be happy to convert the int 4 to a long or an Integer. So if it can convert it to an Integer, why can't it convert it to a Long?



Method conversions are specified by section 5.3 of the JLS ... https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.3

In this section, is a list of available options. None of those options include an implicit widening followed by a boxing operation.

Henry
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic