I have come up with a semantic for const values. Its a bit complex, but I think it will work. Its probably too late for const to be in mustang, but I hope it will be available in dolphin.
this is considered readonly. Readonly methods are non-external.
Getting a value from an array is considered constant.
Readonly methods may modify parameters if not declared constant.
(Constant methods are the same as readonly methods). Constructors cannot be readonly.
Method may only call non-external methods. May not reference static methods/fields unless either field or method is constant, or static method/field is declared in same class and method is static. (wait and notify should not be non-external).
All methods must be readonly or initializer. Initilizer methods must be non-external. Initilizers/constructors may not call non-initilizer methods. this is considered constant for all constant methods.
final, may only be assigned from another constant reference or from a non-external constructor invocation. May not invoke non-constant methods, all fields of object are considered constant. May not assign a constant reference to a non-constant or non-readonly reference unless the class of the reference is const.
A reference which is constant except, you may not assign readonly references to constant references. Readonly references are not necessarily final. Normal references may be assigned to readonly references. The reverse is however not true. You cannot assign readonly references to normal references.
Must not be public. May only be called by constructors or other initilizer methods.
Static Initilizers may only be called by other static initializes or by the class constructor. Static Initilizers must be private. Constructors are considered Initilizer methods, except they may be called as they normally are.
Just like constant classes, except that this is not considered constant.
Method guarantees that its state will not change when called. Const methods are an alias for readonly methods. Giving same parameters will result in same change of those parameters/return value.
Class instances will never change after constructor is finished. Calling the same constructor with the same parameters results in an equivalent instance.
method will not change anything on the outside of itself or depend on any outside states.
reference will never change.
All access to a readonly reference will not change the object, however the object can be changed externally (though a non-readonly reference to the object).
All methods of the class will not alter its state. Subclasses may however change the state of the class. Methods in readonly classes are not necessarily readonly. Invoking a constructor from a readonly class results in a const object.
methods for initializing the method, and are only called during the initialization of the instance.
You may change readonly to const, or remove readonly. (this includes generic declarations on a class or a method).
you may override a method and provide a more restrictive modifier.
not restrictive: no modifier
more restrictive: readonly
most restrictive: const
Return values follow the same rules as parameters.
Object is a readonly class.
Since java uses erasure in generics, changing a generic declaration from readonly to const (of a type that is not const), will require that the caller wrap the passed parameter in a ConstantReference class which would merely have a single public const field for the const value (ConstantReference is a const class and thus can be assigned to non-const references). This is done by the compiler.
If you declare a generic parameter that extends a readonly parameter you cannot declare a non-final(or non-const/non-readonly) instance variable of that type. This is because if the type was const the runtime would not be able to enforce reassignment of that field. (Arrays are still ok)
Classes like Vector can accept (and return) const references:
Assume all of Point