Win a copy of Rust Web Development this week in the Other Languages 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Java 1.5 Autoboxing parameters

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



Why doesn't the 5 get autoboxed into an Integer wrapper? (Well, at least in Java 1.5 beta 2 it don't)

[Update: seems that this could be a problem with the IDE Eclipse 3.1M1 I'm using]
[ August 25, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why you not compile ???

I'm tested in my computer , it work fine...


please post your error...
[ August 25, 2004: Message edited by: somkiat puisungnoen ]
 
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Autoboxing surprises here
http://jroller.com/comments/eu/Weblog/autoboxing_surprises#comments
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry Gaunt,
I can successfully compile your code as well, using JDK 5.0 beta 2...

I'm afraid you are still using beta 1? :roll:
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:
Autoboxing surprises here
http://jroller.com/comments/eu/Weblog/autoboxing_surprises#comments



The link got very interesting topic for me... I was amazed of the following in the link...


Integer j1 = 127;
Integer j2 = 127;
System.out.println( j1==j2); //Works!!!

Integer k1 = 128;
Integer k2 = 128;
System.out.println( k1==k2); //Doesn't Work!!!

Integer w1 = -128;
Integer w2 = -128;
System.out.println( w1==w2); //Works!!!

Integer m1 = -129;
Integer m2 = -129;
System.out.println( m1==m2); //Doesn't Work!!!



Thanks for your great info, Pradeep...
 
Pradeep bhatt
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please do a

java -version

Just to make sure that you are using the Tiger.
 
Pradeep bhatt
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ko Ko,
Be prepared for surprises when you use Tiger.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm actually compiling this program with Eclipse SDK 3.1M1 set up to use the Java 1.5 beta 2 and jre. And its complaining with the error message:

The method add(int, Integer) in the type List<Integer> is not applicable for the arguments (int)Template1.java




However, due to the vigourous responses to my query, I went back to trying it from the command line and lo' and behold it works. So that points to a problem with Eclipse SDK 3.1M1.

Thanks
-Barry

PS Looks like Eclipse uses its own compiler, and it's not up to full complience with Java 1.5 yet. Bleeding Edge Early Adopters beware.
[ August 25, 2004: Message edited by: Barry Gaunt ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic