我正在学习我在 C# 中找到Static Constructor
的 C# 和 JAVA,它们用于初始化任何静态数据,或执行只需要执行一次的特定操作。在创建第一个实例或引用任何静态成员之前自动调用它。
例如:
class SimpleClass
{
// Static variable that must be initialized at run time.
static readonly long baseline;
// Static constructor is called at most one time, before any
// instance constructor is invoked or member is accessed.
static SimpleClass()
{
baseline = DateTime.Now.Ticks;
}
}
我的问题是我怎样才能在 JAVA 中获得相同的功能有什么办法吗???