By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

immutability & composition

P: n/a listing 7-11:
If the following code is written in a package seperate from the
Location class, it will now cause compile-time errors:

Location loc = body.getLocation();
loc.x = 5; //field x is not accessible;
loc.setX(5); //method setX not found in class Location

Be aware, however, that it is possible to cast the returned Location
object to a MutableLocation. The following code will work and is
quite dangerous.

Location loc = body.getLocation();
MutableLocation mLoc = (Mutable)loc;

Listing A-1:
public class CatTest{
static Vector catList = new Vector();
static void makeCat() {
Object cat = new Cat();

public static void main(string[] arg) {
// do more stuff

I'm using this "pattern," but solely with immutable classes at

unfortunately, when I try to do things, like change x coordinate in a
location object, I'm not getting the result I want. I'm looking for
constructive criticism, please.

Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.