This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Immutables and Multi-valued Returns
Posted by Bill Venners on April 26, 2000 at 1:58 PM
> Hello Bill,
> thanks for answering my question
> > If there is no solution: Why may one make something in Java
> > with arrays, what is forbidden with normal objects?
> Your answer was:
> > Class Integer happens to be immutable. Once it is created with
> > a value, it can't change. Arrays are always mutable.
> Is there for it a simple reason? I cannot believe that it is so difficult to implement a simple algorithm calculating two or more integers.
1. Immutables are by definition thread-safe.
2. Immutables needn't be cloned before being passed, because
the method to which they are passed can't change their state.
If you want to do a multi-valued return, you'll have to return
an object that contains the values. For an example, search
for "Multi" in the following seminar handout:
This page also discusses immutables.