You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Caldarale, Charles R" <Ch...@unisys.com> on 2007/05/22 16:44:48 UTC

RE: [OT] "if" don't work?!?!?

> From: Massimiliano PASQUALONI 
> [mailto:massimiliano.pasqualoni@data-processing.it] 
> Subject: "if" don't work?!?!?
> 
>    if (Pippo == "on") {

Guaranteed to be false.

>     Pippo =  request.getParameter("abilitato");
>     Pluto =  request.getParameter("abilitato");
>  
> the if (Pippo == Pluto )  don't work!

Also guaranteed to be false.

You need to learn Java before embarking on writing webapps for any
container.  The test you're making is one for object equality, not
content equality.  Your expression should be something like:

    if (Pippo.equals("on"))

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [OT] "if" don't work?!?!?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Jost Richstein [mailto:jrichstein@softdecc.com] 
> Subject: Re: [OT] "if" don't work?!?!?
> 
> No, that is not guaranteed to be false.
> For example
>    Pippo.intern() == Pluto.intern()
> should be true.

The above certainly is correct, but is not what the OP coded.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] "if" don't work?!?!?

Posted by Jost Richstein <jr...@softdecc.com>.
No, that is not guaranteed to be false.
For example

   Pippo.intern() == Pluto.intern()

should be true.

Caldarale, Charles R schrieb:
>> From: Massimiliano PASQUALONI 
>> [mailto:massimiliano.pasqualoni@data-processing.it] 
>> Subject: "if" don't work?!?!?
>>
>>    if (Pippo == "on") {
>>     
>
> Guaranteed to be false.
>
>   
>>     Pippo =  request.getParameter("abilitato");
>>     Pluto =  request.getParameter("abilitato");
>>  
>> the if (Pippo == Pluto )  don't work!
>>     
>
> Also guaranteed to be false.
>
> You need to learn Java before embarking on writing webapps for any
> container.  The test you're making is one for object equality, not
> content equality.  Your expression should be something like:
>
>     if (Pippo.equals("on"))
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>
>   

-- 
Jost Richstein
SoftDeCC Software GmbH
Email: jrichstein@softdecc.com
Tel.: +49 89 89 06 78 47
Fax.: +49 89 89 06 78 33

SoftDeCC Software GmbH; Gesellschaft mit beschränkter Haftung; Sitz der Gesellschaft: München; Registergericht: München, HRB 123667; Geschäftsführer: Ralf Malis, Georg Nüssel, Jost Richstein, Gerd Wilts



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] "if" don't work?!?!?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

Caldarale, Charles R wrote:
>> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
>> Subject: Re: [OT] "if" don't work?!?!?
>>
>> String Pippo = "on";
>>
>> if(Pippo == "on")
>>    System.err.println("Pippo is on, man!");
> 
> Again, that's not what the OP coded; Pippo was retrieved from the
> request, not set to a constant.  Changing the context of the if
> statement can certainly changes the result.

Agreed. Your quote, however, was out of context. You only showed the
comparison between a (most likely String) reference type and a literal
string and asserted that it was guaranteed not to work. In that context
(i.e. none), your statement was not true.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD4DBQFGU0vc9CaO5/Lv0PARAptfAJd/xAWaVEtfhSAnSYhGMvKGqpEVAJ9KE5hq
BvycOhmewUhMklkNDbeatg==
=wizm
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [OT] "if" don't work?!?!?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
> Subject: Re: [OT] "if" don't work?!?!?
> 
> String Pippo = "on";
> 
> if(Pippo == "on")
>    System.err.println("Pippo is on, man!");

Again, that's not what the OP coded; Pippo was retrieved from the
request, not set to a constant.  Changing the context of the if
statement can certainly changes the result.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] "if" don't work?!?!?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

Caldarale, Charles R wrote:
>> From: Massimiliano PASQUALONI 
>> [mailto:massimiliano.pasqualoni@data-processing.it] 
>> Subject: "if" don't work?!?!?
>>
>>    if (Pippo == "on") {
> 
> Guaranteed to be false.

Not always:

String Pippo = "on";

if(Pippo == "on")
   System.err.println("Pippo is on, man!");

...will print the string ;)

But, of course, this is a /super/ special case where Java's constant
pool is involved. Someone who doesn't understand why "Pippo == "on"
doesn't always work is going to have their mind blown by the constant pool.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGUzc99CaO5/Lv0PARAoktAJ0aTbR2XlrB3CD6PjMUlEsJMIO0pwCgn1zy
SwD0cbGDStbYkxoYtcummaI=
=J+fl
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org