immutable « primitive « Java Data Type Q&A





1. Why are wrapper objects (to primitive data types) immutable?    coderanch.com

Welcome to JavaRanch. The reason why your code doesn't work has nothing to do with immutability. If you would have used int instead of Integer, you would have gotten the same result. Your code does not produce the output you expect because Java passes arguments to methods by value - which means, if you pass a variable to a method, only ...

2. Why are all primitive wrappers immutable?     coderanch.com

Hi, I have got following stuff from net: The main reason why String made immutable was security. Look at this example: We have a file open method with login check. We pass a String to this method to process authentication which is necessary before the call will be passed to OS. If String was mutable it was possible somehow to modify ...

3. Time to revisit the primitive immutable wrapper objects in the java.lang package?    coderanch.com

Is it time to revisit the primitive wrapper objects in the java.lang package? I think Java's early attempts at object wrappers aren't ideal and lead to arguments about when to use objects vs primitives. Primitive types always win out over objects because of their speed, changeability, and lower memory requirements. Of course this argument misses the point entirely, especially because often ...

4. getting/setting values for Immutable primitive wrappers    forums.oracle.com

i have two objects. i need to share an Integer value between then. borh need to be able to increase/decrease the integer value. java.lang.Integer is immutable.... so, my ultra-lame solution is to pass a Collection and add/remove objects. and the use the "size" of the collection as my integer value. is there a better way? basic code: .... Integer intObj = ...