Java 静态块相当于 C# 静态构造函数吗?
C# 静态构造函数和 Java 静态块之间的真正区别是什么?
它们都必须是无参数的。 当相关类首次使用时,它们都只被调用一次。
我是否遗漏了什么,或者它们是同一件事,只是名称不同?
What is the real difference between a C# static constructor and a Java static block?
They both must be parameterless.
They are both called only once, when the related class is first used.
Am I missing something, or are they the same thing, just with different names?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(4)
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
它们是等效的,只是 C# 类只能有一个静态构造函数(加上静态字段初始值设定项)。
此外,在 C# 中,
static
构造函数将应用beforefieldinit
标志。They are equivalent, except that a C# class can only have one static constructor (plus static field initializers).
Also, in C#, a
static
constructor will apply thebeforefieldinit
flag.