Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapper classes are pass by value or pass by reference?

Tags:

java

I know java is pass by reference but only for Java Objects. But why it is not applicable for Java Wrapper classes? Are Wrapper classes such as Integer, Float, Double pass by reference or pass by value? Because whenever I pass object of such classes in method and that changes some values, but outside of that method I am not getting updated Value.

like image 949
Arvind Chavhan Avatar asked Oct 21 '25 11:10

Arvind Chavhan


1 Answers

On top of pass by value discussion, all wrapper classes in Java are immutable. They replicate the behaviour of primitives. You need to return the latest value back to see the changes.

like image 111
Suresh Atta Avatar answered Oct 22 '25 23:10

Suresh Atta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!