In testing the performance of Integer objects in various settings, I discovered what may be a "secret" clone of the Integer object when used as a method parameter. My test passed a reference to an Integer object as a method parameter and then expected to print the new value for the Integer object which was computed by the called method. According to my documentation, this should have worked because the Integer reference variable was passed by value to the called method. Is the Integer object being cloned unbeknowst to me when I use a reference to it as a parameter to a called method?
Could you post this code? (And Sheriff, I don't care about the book, I'm actually interested )
Joined: Nov 02, 2000
Michael I was getting ready to post you this code when I realized that the whole thing is just a mistake on my part. Since Integer is immutable a side effect could never be expected. Sorry, my problem. I needed a side effect, so I created my own wrapper class MyInteger which has an increment method etc. Then, when I pass MyInteger as a parameter to a method, and the method runs the increment method, the calling program gets to see this side effect.
subject: secret clone discovered in performance test of Integer