The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2000

Advertisement

Advertisement
where you can ask and answer Java programming questions.">
artima.com - a resource for Java and Jini developers
Artima | Search | Java | Design | JVM | Jini | Books | Seminars | Subscribe 


Java Answers Forum
April 2000

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 Artima Forums.

Message:

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:
> --snip
> > Class Integer happens to be immutable. Once it is created with
> > a value, it can't change. Arrays are always mutable.
> --snip
> 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:

http://www.artima.com/javaseminars/modules/DesWithObjects/index.html

This page also discusses immutables.

bv



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us