Monday, August 8, 2011

Fields

Anyone know a better way to ensure that a subclass defines a number of fields without forcing it through a constructor?  Java doesn't permit an abstract field, which I'd forgotten about.  The problem is that I may have up to 30 points of data, all numbers, and there's a pretty strong risk that I'll get a couple of them mixed up.  What I'd like is in the class declaration to set them without marshaling them through a constructor call, but still have the compiler enforce that I have in fact set them all.  This should all happen without copying and pasting the field definitions, etc.  I can think of how I'd do this in a number of other languages, but not Java.

1 comments: