+ 5
Why does C# have static constructors whereas Java does not?
It seems that the Java alternative to this is static initialisation blocks and the C++ way is to have static inner classes. The purpose of all these seem to be the initialisation of static members of a class. Is my understanding correct?
2 ответов
+ 7
I think this also helpful:
https://stackoverflow.com/questions/4506990/what-is-the-use-of-static-constructors
"A static constructor is used to initialize any static data, or to perform a particular action that needs performed once only. It is called automatically before the first instance is created or any static members are referenced."
+ 3
I don't know why c# has static constructors but here is an explanation why java can not have static constructors:
https://beginnersbook.com/2013/05/static-constructor/