File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Integer : pass by value ?

 
Edward Chen
Ranch Hand
Posts: 798
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tested pass-by-value and pass-by-reference , found the Integer will be passed by value ? why ? it is because Integer is wrapper class of primitive type ?

Thanks.

 
Paul Clapham
Sheriff
Pie
Posts: 20184
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's much simpler than that. It's because all parameters are always passed by value in Java. You can read this Ranch campfire story which explains why that is.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lots of people get very confused about that. There are lots of explanations in this thread
 
Edward Chen
Ranch Hand
Posts: 798
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:No, it's much simpler than that. It's because all parameters are always passed by value in Java. You can read this Ranch campfire story which explains why that is.


Thanks. Lots of discussions.

as said: "For references to objects, you pass a copy of the reference (the remote control)", reference is the address of the object, so we can say pass by object (reference), On the other side, reference is address, (0x1234), still is a value, so we can say we are passing a value. From this point of view, no any different.

Another question, Integer is an immutable class, like String ?

Thanks.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edward Chen wrote:
Another question, Integer is an immutable class, like String ?


Yes. The Javadoc says so.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure, Ernest; I can't find "immutable" in the documentation. It says "immutable" in BigInteger, however, for example.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic