Skip to content

Annotating custom constructor methods for generic types. #2025

Answered by erictraut
randolf-scholz asked this question in Q&A
Discussion options

You must be logged in to vote

Any idea why it fails to bind V=int (or possibly V=Literal[3])?

Yes, Foo.new binds Foo[Any, Any] to the new method. The types of class-scoped type variables are inferred from argument types only when you call a constructor. This doesn't work for other methods. In other cases, the specialization comes from the bound class — in this case, Foo or Foo[Any, Any] since you haven't specified any default values for the type variables.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@randolf-scholz
Comment options

@erictraut
Comment options

Answer selected by randolf-scholz
@randolf-scholz
Comment options

@randolf-scholz
Comment options

@randolf-scholz
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants