因此,在C#中我最喜歡做的事情之一是:Java相當於以下靜態只讀C#代碼?
public class Foo
{
public static readonly Bar1 = new Foo()
{
SomeProperty = 5,
AnotherProperty = 7
};
public int SomeProperty
{
get;
set;
}
public int AnotherProperty
{
get;
set;
}
}
我怎麼會寫這在Java中?我想我可以做一個靜態的最終字段,但我不知道如何編寫初始化代碼。 Enums會成爲Java領域的更好選擇嗎?
謝謝!