[Checkers] <@ReadOnly Object> generic type (fwd)

Michael Ernst mernst at csail.mit.edu
Wed Mar 26 09:44:13 EDT 2008

Thanks for the good discussion on this issue.  I have a couple points to

We know that

  class C<T>

is really shorthand for

  class C<T extends UltimateSupertype>

In normal Java, UltimateSupertype is "Object", but in Javari/IGJ, it is
"@Readonly Object".

Here are 3 examples of how we should treat "class C<T extends Something>".

1. The proposed solution of treating 

  class C<T>

as shorthand for 

  class C<T extends @Readonly Object>

seems right to me.  (This was the intention all along, but I guess no one
ever noticed the issue before, perhaps because the implementation wasn't
completely finished.)

2. There's a separate question of whether we should treat

  class C<T extends Object>

as shorthand for 

  class C<T extends @Readonly Object>

I tend to lean toward doing so, mostly because Object has no methods with
mutable receiver, and so this treatment cannot cause a problem.

3. Finally,

  class C<T extends Date>

should *not* be shorthand for 

  class C<T extends @Readonly Date>

Date has methods with mutable receiver, so this is a change of semantics.

These examples suggest a generalization.  For methods with no (possibly
inherited) methods with mutable receiver, make "extends Foo" equivalent to
"extends @Readonly Foo".  Otherwise, "extends Foo" is equivalent to
"extends @Mutable Foo".

Does this proposal work, or am I missing something?

I suggested this proposal because treating Object specially feels wrong to
me.  I would rather find a rule that handles both Object and other classes,
for two reasons.  First, it explains *why* Object is treated specially.
Second, it will preserve backward-compatibility in more cases, such as

  class C<T extends Comparable<T>> 




More information about the checkers mailing list