Bom, s� pra dar uma corrigida :
( tirado da especificacao de java )
- Literal strings within the same class in the same package represent
references to the same String object.
- Literal strings within different classes in the same package represent
references to the same String object.
- Literal strings within different classes in different packages
likewise represent references to the same String object.
- Strings computed by constant expressions are computed at compile time
and then treated as if they were literals.
- Strings computed at run time are newly created and therefore distinct.
Isso significa que o exemplo abaixo :
| String a1 = "A";
| String a2 = "A";
|
| if (a1 == a2){//compara se � o mesmo Handle e n�o �!!!!
| SOP("Nunca ir� imprimir isso");
| }
| if (a1 == "A"){//compara se � o mesmo Handle e n�o �!!!!
| SOP("Nunca ir� imprimir isso");
| }
| if (a1.equals(a2)){
| SOP("Isso ser� impresso");
| }
| if (a1.equals("A")){
| SOP("Isso ser� impresso");
| }
| a1 = a2;
| if (a1 == a2){
| SOP("isso ser� impresso");
| }
Escrever� :
Nunca ir� imprimir isso
Nunca ir� imprimir isso
Isso ser� impresso
Isso ser� impresso
Isso ser� impresso
Al�m disso, algo do tipo :
String s1 = "Oi mundo";
if (s1 == "Oi " + "mundo")
SOP ("Isso � escrito, a string � concatenada em tempo de
compila��o");
:: marcelo alves ::
:: marcelo alves ::
------------------------------ 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]
-------------------------------------------------------------------------