tenho uma dúvida básica...
Sempre que eu der um over na toString() em uma classe X, e chamar um objeto desta classe, ele vai me retornar a String?
Se sim, SEMPRE? Senão, quais as condições?
como por exemplo:
public class Increment {
private int total = 0; // total de todos os incrementos
private final int INCREMENT;
/** Construtor inicializa variável de instancia final INCREMENT */
public Increment( int incrementValue ) {
INCREMENT = incrementValue;
}
/** adiciona INCREMENT ao total */
public void addIncrementToTotal() {
total += INCREMENT;
}
/** Retorna representação de String dos dados de um objeto Increment */
public String toString() {
return String.format("total = %d", total);
}
}
e...
/**
* Created by IntelliJ IDEA.
* User: Usuário
* Date: 14/11/2006
* Time: 16:35:17
* To change this template use File | Settings | File Templates.
*/
public class IncrementTest {
public static void main ( String args[]) {
Increment value = new Increment(5);
System.out.printf("Before incrementing: %s\n\n", value);
for( int i = 1; i <=3; i++) {
value.addIncrementToTotal();
System.out.printf("After increment %d: %s\n", i, value);
}
}
}
Sempre que chamo o objeto Increment value ele me retorna a String formatada.
obrigado!