http://java.sun.com/docs/books/performance/ 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;
mLoc.setX(5);
Listing A-1:
------------
public class CatTest{
static Vector catList = new Vector();
static void makeCat() {
Object cat = new Cat();
catList.addElement(cat);
}
public static void main(string[] arg) {
makeCat();
// do more stuff
}
}
I'm using this "pattern," but solely with immutable classes at
http://www.geocities.com/cjavacjava/...LifeForms.java
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.
ja***@mail.com