I wants to swap primitive data types in java, as java uses pass by value for primitive data types , i used wrapper class and passed to the swap function still i am not able to swap the values can you please help...
Below is the code segment for the same....
It won't work this way. Wrapper classes for primitive types are still passed by value, and this classes are immutable (i.e. you can not change their state after creation). So the only way to change variable value by function is to wrap it in mutable class, like the following: and pass instance of this class to the function.
Joined: Oct 13, 2009
Ohh .. Thanks Mathew and Andrey for your suggestions..
It seems that i have made a habit of thinking in c++ style