For further consideration...
Mark Thornton
mthornton at optrak.co.uk
Tue Mar 31 02:08:32 PDT 2009
David Goodenough wrote:
> On Monday 30 March 2009, Mark Thornton wrote:
>
>> David Goodenough wrote:
>>
>>> 5 years as near to indefinitely as matters). I need compiler
>>> checkability for field references now.
>>>
>> Define an annotation
>>
>> @interface @fieldReference {
>> String name();
>> }
>>
>> class MyClass {
>> @fieldReference("myField") static FieldRef FIELD_REF;
>>
>> static {
>> // use reflection to set initialise static fields with
>> @fieldReference annotations
>> }
>> }
>>
>> You could use an annotation processor to verify that the @fieldReference
>> named valid fields and was attached to a suitable reference field. There
>> are probably other ways of doing this, but it does give you the compile
>> time check you want without requiring a language change.
>>
>> Regards
>> Mark Thornton
>>
>
> My first instinct when I read this was that this was another example of
> moving the problem to a better place (the place where the field originates
> rather than the place where you use it) but that it was still uncheckable.
>
>
...
> The only niggle that strikes me immediately is that existing beans will
> not be suitably annotated, and this includes all the Swing screen widgets
> (subclassing or a helper class can solve that as it is a well defined set)
> and classes built by schema scrapers from places like existing SQL
>
You could add an optional field to the annotation which specifies the
class defining the field. This would default to null, meaning the
current class if not specified. Now you can declare them anywhere and
don't need to modify existing classes. Someone with more experience with
annotation processors than I have could probably come up with a much
neater scheme.
> I will have to try this and see if it solves the problem. If it does then I
> will happly withdraw my proposal, and stop getting in everyone's hair.
>
Although your proposal isn't large in itself, it intersects with many
other proposals in the same area which are clearly large (and outside
the scope of Coin). This makes it difficult to consider without also
evaluating those other proposals.
Anyway I hope my suggestion allows you to get the compile time
validation you want without waiting another month let alone a year or
even 5 years.
Mark Thornton
More information about the coin-dev
mailing list