我已经使用C#很长时间了,现在我需要在Java中做一些事情。
Java中是否有类似于C#结构体自动构造函数的东西?
我的意思是,在C#中
struct MyStruct
{
public int i;
}
class Program
{
void SomeMethod()
{
MyStruct mStruct; // Automatic constructor was invoked; This line is same as MyStruct mStruct = new MyStruct();
mStruct.i = 5; // mStruct is not null and can i can be assigned
}
}
是否可能在声明时强制Java使用默认构造函数?