Is it good or bad practice auto-generating toString
methods for some simple classes?
I was thinking of generating something like below where it takes the variable names and produces a toString
method that prints the name followed by its value.
private String name;
private int age;
private double height;
public String toString(){
return String.format("Name: %s Age: %d Height %f", name, age, height);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…