Win a copy of Spring Boot in Practice this week in the Spring 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:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Does Java, sometimes, do automatic type conversion?

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've become a bit confused at times when I have accessed bean properties. For example, I have a bean that in one scenario should have a property, an array, that is null, but when I access it its an array of length 0 instead.

Another weird behaviour is with say bean1 with an Integer property and bean2 with a String property. At one point I want to do bean1.IntegerProp -> bean2.StringProp. So I wrote: And it compiles and works. But when I think about it, it shouldnt work. Because Integer.toString() doesnt take an Integer as argument, only int. Where's the magic?

seb
 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by seb petterson:
And it compiles and works. But when I think about it, it shouldnt work. Because Integer.toString() doesnt take an Integer as argument, only int. Where's the magic?



if you're using Java 5, the magic is in autoboxing. it's a new feature in that version. if you're using java 1.4 or earlier, then you're right, that shouldn't work.
reply
    Bookmark Topic Watch Topic
  • New Topic