Posted By:
David_Bates
Posted On:
Thursday, May 8, 2003 03:12 AM
(Please see my post about ordering, it's a little lost among the posts).
One thing to consider about the 'final' modifier. It does not mean "the value cannot be changed". What it means is "the variable may not be re-assigned". For example:
public class OrderCount {
private int count;
public void incrementCount() {
this.count++;
}
}
public class Order {
public static final OrderCount totalNumberOfOrders = new OrderCount(0);
...
public void processOrder() {
// totalNumberOfOrders contains '0'
totalNumberOfOrders.incrementCount();
// totalNumberOfOrders contains '1'
}
}
This example is a little contrived, but the point about 'final' is still valid - the object may be "changed", but it just can't be "re-assigned".
This point shouldn't concern you when dealing with primitives or immutable objects (such as String), but you should be careful with more complex objects.