Description
I love the primary constructor syntax in the views proposal. I really want that syntax for classes too. Based on that, I think we should require a final
modifier when defining a primary constructor on a view:
view class V(final int x) {
...
}
I'm assuming we will eventually do primary constructors for classes. When we do, I believe fields should default to non-final. That's consistent with how both parameter declarations and field declarations work today. It's also consistent with the view proposal that requires you to write final
if you declare the representation as an instance field inside the body.
Requiring final
is a tiny amount of verbosity and we get consistency and clarity in return. The verbosity doesn't bother me much because I don't anticipate a large number of users authoring view types. A much larger number of them will end up reading them when they go to definition. When they do, since the feature may be unfamiliar, I think it helps for the syntax to be clearer and seeing the final
there can help them understand that the underlying representation field can't be assigned by the view.