• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • 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.
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic