[Grace-core] Visibility of variables and constants in Objects

Lex Spoon lex at lexspoon.org
Fri Jul 5 09:54:28 PDT 2013


On Fri, Jul 5, 2013 at 9:33 AM, James Noble <kjx at ecs.vuw.ac.nz> wrote:
> (BTW I thought of a use case for fields overriding methods - implementing an abstract field :-)

Here's a use case I have seen in the wild: hash codes.  Sometimes you
want to compute a hash code algorithmically, every time it is asked
for. Other times, you want to compute it once and keep it in a field.

This example caught me by surprise when I wrote a lint query for
keeping equals and hashCode in sync. Without thinking about it, I
wrote my query to look for hashCode *methods*. I quickly learned that
lots of real-world Scala code has a hashCode *field*. Such fields
override the Java's hashCode method in class Object. This method
happens to be concrete.

Lex


More information about the Grace-core mailing list