Skip to content
Discussion options

You must be logged in to vote

Java doesn't have generics at runtime and so all static methods on a generic class are actually the same. In C# this is not the case - theoretically a different method is compiled for every type parameter used in static method (ignoring done optimisations to share generated code) and so the type parameter must be set.

E.g, this is legal in c#:

static class A<T> where T : struct
{
     static object New() => new T();
}

A.New(); //what would this return?

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@qhc99
Comment options

Answer selected by 333fred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #4374 on January 31, 2021 04:20.