I have taken to using setters instead of putting arguments into the default constructor because it helps me organise my code better
The problem is that the only variable on a project I am doing is a String and I am not sure whether I should be initializing it in the declaration (as a global variable?), in an setter instance method or whether to initialise it in the class constructor.
I am wondering if there could be anything problematic about this set up whether the instance is not initialised until it's setter is used:
class MyClass{
private String myString;
public MyClass(){
}
public void setStuff(String s){
this.myString=s;
}
}
Why not just initialize as:
private String myString = "My string";
The easiest way possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With