Everson, Vamos lá:
1) O método finalize() é executado no momento em que o Garbage Colector tenta liberar a memória de um objeto que não mais está sendo utilizado. Antes de liberar a memória o método finalize associado a esse objeto é executado, e somente depois o GC libera a memória. Aí vai um exemplo... public class GCTest { public static void main(String[] args) { Blah a = new Blah(); Blah b = new Blah(); Blah c = new Blah(); a.i = 1; b.i = 2; c.i = 3; b = a; // O objeto 'b' passa a apontar para // a mesma referência do objeto 'a' System.out.println( "a:" + a.i + ", b: " + b.i + ", c: " + c.i); System.gc(); // Sugere a execução do GC } } class Blah { int i; protected void finalize() { System.out.println( "Valor de 'i' para o objeto coletado pelo GC: " + this.i); } } 2) Maior clareza do código. 3) Retorna uma referência ao objeto atual. Espero ter ajudado. []'s Ruy Ruy Pedroso Trails Sistemas Av. Nilo Peçanha 50 - sala 2511 - Centro CEP 20020-100 - Rio de Janeiro - RJ Tel: +55 21 2262 6370 Fax: +55 21 2262 6354 -----Original Message----- From: everson [mailto:[EMAIL PROTECTED]] Sent: sexta-feira, 24 de janeiro de 2003 14:17 To: [EMAIL PROTECTED] Subject: [java-list] duvidas -> finalize() + this 1) alguem pode me explicar como funciona o métode finalize() ? Algum exemplo !? ********** 2) Nas situacoes em q this é opcional, qual a vantagem no seu uso ???? 3)Alguem pode me explicar oq this retorna nos 2 metodos abaixo: public Time4 setHour( int h ) { this.hour = ( ( h >= 0 && h < 24 ) ? h : 0 ); return this; // enables chaining } public Time4 setTime( int h, int m, int s ) { this.setHour( h ); // set the hour this.setMinute( m ); // set the minute this.setSecond( s ); // set the second return this; // enables chaining } ************************************************************************ **** *************************** import java.text.DecimalFormat; // used for number formatting public class Time4 extends Object { private int hour; // 0 - 23 private int minute; // 0 - 59 private int second; // 0 - 59 public Time4() { this.setTime( 0, 0, 0 ); } public Time4( int h ) { this.setTime( h, 0, 0 ); } public Time4( int h, int m ) { this.setTime( h, m, 0 ); } public Time4( int h, int m, int s ) { this.setTime( h, m, s ); } public Time4( Time4 time ) { this.setTime( time.getHour(), time.getMinute(), time.getSecond() ); } public Time4 setTime( int h, int m, int s ) { this.setHour( h ); // set the hour this.setMinute( m ); // set the minute this.setSecond( s ); // set the second return this; // enables chaining } public Time4 setHour( int h ) { this.hour = ( ( h >= 0 && h < 24 ) ? h : 0 ); return this; // enables chaining } public Time4 setMinute( int m ) { this.minute = ( ( m >= 0 && m < 60 ) ? m : 0 ); return this; // enables chaining } public Time4 setSecond( int s ) { this.second = ( ( s >= 0 && s < 60 ) ? s : 0 ); return this; // enables chaining } public int getHour() { return this.hour; } public int getMinute() { return this.minute; } public int getSecond() { return this.second; } public String toUniversalString() { DecimalFormat twoDigits = new DecimalFormat( "00" ); return twoDigits.format( this.getHour() ) + ":" + twoDigits.format( this.getMinute() ) + ":" + twoDigits.format( this.getSecond() ); } public String toString() { DecimalFormat twoDigits = new DecimalFormat( "00" ); return ( ( this.getHour() == 12 || this.getHour() == 0 ) ? 12 : this.getHour() % 12 ) + ":" + twoDigits.format( this.getMinute() ) + ":" + twoDigits.format( this.getSecond() ) + ( this.getHour() < 12 ? " AM" : " PM" ); } } ------------------------------ LISTA SOUJAVA ---------------------------- http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP dúvidas mais comuns: http://www.soujava.org.br/faq.htm regras da lista: http://www.soujava.org.br/regras.htm historico: http://www.mail-archive.com/java-list%40soujava.org.br para sair da lista: envie email para [EMAIL PROTECTED] ------------------------------------------------------------------------ - --- Incoming mail is certified Virus Free.O email foi inspecionado por vírus. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.449 / Virus Database: 251 - Release Date: 27/1/2003 --- Outgoing mail is certified Virus Free.O email foi inspecionado por vírus. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.449 / Virus Database: 251 - Release Date: 27/1/2003 ------------------------------ LISTA SOUJAVA ---------------------------- http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP dúvidas mais comuns: http://www.soujava.org.br/faq.htm regras da lista: http://www.soujava.org.br/regras.htm historico: http://www.mail-archive.com/java-list%40soujava.org.br para sair da lista: envie email para [EMAIL PROTECTED] -------------------------------------------------------------------------