-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Primary constructor type parameter syntax #3172
Comments
It should be |
I feel current specification reasonable. because,
|
It's the name of the class, at least according to how the spec reasons about this. The constructor doesn't have a name in this case. (If it were the name of the constructor, then
But the type parameters are not on the function, they are on the class.
Not currently, but this a long-running feature request: #647.
They can. We anticipated that when adding constructor tear-offs by letting you write class C {
C.new<T>() { ... }
} |
This was a dilemma. As proposed, the constructor name is shown (so it's readable and searchable). If the class is generic then the type parameter list needs to go somewhere, and I put it after the complete constructor name. Of course, this conflicts with the constructor invocation syntax, but it is arguably similar to the current constructor declaration syntax (for those, there is no type parameter list, so we never have anything between the class name and the other half of the name of a named constructor). We could also simply make it a syntax error to have both a type parameter list and a named primary constructor at the same time. This means that the primary constructor will also have to be the "nameless" one in a generic class. In return, we won't ever have this funny configuration where the constructor name has a (perhaps long) type parameter list in the middle. Another possibility is to say that the type parameter list goes in the same position as in the constructor invocations, and we don't care that a constructor named I don't have a strong opinion here. |
This is what I prefer, definitely. Users are always apparently entirely comfortable reading code like |
Ok, now I agree with @munificent , |
I'm strongly for There are pragmatic reasons too, like being prepared for generic constructors, but mainly the latter just looks like a mistake. NUXI |
Cool, let's do |
The proposed syntax for a generic class with a named primary constructor (#3023) is:
It feels to me like it should be:
The type parameters are a property of the class itself, not the constructor. The syntax for invoking a named constructor on a generic class is:
Also, if we ever want to support generic constructors, we may find ourselves wanting to allow:
The text was updated successfully, but these errors were encountered: