toString method for varargs contructor
- by owca
I have a varargs contructor like this :
public class Sentence {
public String[] str;
public Sentence(Object... text){
StringBuilder sb = new StringBuilder();
for (Object o : text) {
sb.append(o.toString())
.append(" ");
}
System.out.println(sb.toString());
}
}
Contructor can get various types of data (ints, strings, and Sentence objects as well). How to do a proper toString method for such class ?