For instance:
public class Foo {
private int bar = 42;
Foo() {}
}
vs
public class Foo {
private int bar;
Foo() {
bar = 42;
}
}
Is there any cost/benefit between the two methods? The only way I could see it making a difference is in a scenario like this (where you're setting a value twice for the second constructor):
public class Foo {
private int bar = 42;
Foo() {}
Foo(int in) {
bar = in;
}
}
vs (where either way you're only setting it once)
public class Foo {
private int bar;
Foo() {
this(42);
}
Foo(int in) {
bar = in;
}
}
Am I missing something? Is there any inherent value in doing it one way or the other?
<EDIT> Ok, I realize these are functionaly equivalent, What's I'm trying to figure out is if there are any significant processing costs associated with one over the other. Seems like it should be negligable, at best, but I'd like confirmation of my suspicions. </EDIT>
<EDIT2> I also realize that manually setting them eliminates the possibility of initilization logic. That's why I chose such simple examples. I edited the question text to reflect that what I'm interested in is efficiency. </EDIT2>