Ste*_*fan 4 java design-patterns coding-style
我正在与一些同事讨论Java构造函数,设计模式以及使用非参数化构造函数初始化对象的好方法,如果我通常等待一些参数的话.
其中一个较老的人提出了他的实现方式总是如下:
public class Foo {
public Foo() {
this(0,0,0);
}
public Foo(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
..
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,这是好风格,它的行为究竟是什么?
从我的理解应该是:
So the GC has then to delete the first created one.
Run Code Online (Sandbox Code Playgroud)
不会.链接构造函数时只创建一个实例.
要回答你的问题,是的,它是好的风格,假设你需要两个foo()和foo(int, int, int)