• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Confusion in EL

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Given the code as below:



The result is true.

Since EL treats null object as false in logical expression and map.c actually exists, does anyone have idea why the result is true?
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe it is because ${requestScope.map.c} returns "42". Since "42".equalsIgnoreCase("true") == false, ${not requestScope.map.c} == true.
 
chou hung
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dee,

Thanks for the reply. That makes sense.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I believe it is because ${requestScope.map.c} returns "42". Since "42".equalsIgnoreCase("true") == false, ${not requestScope.map.c} == true.



Sorry i could not understand the explanation above(in Bold)..if i had missed any topic related to this in HFSJ please tell me the page number so that i can go back and read once again..

Thanks & Regards,
Sudhakar Karnati
 
Dee Brown
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the statement, "${not requestScope.map.c}", the "not" operator coerces the evaluation of "requestScope.map.c" (i.e. "42") to a boolean. In simple terms, a boolean X is true when X.equalsIgnoreCase("true") is true. Therefore, since
"42".equalsIgnoreCase("true") == false, its negation (i.e. ${not requestScope.map.c}) is true.
 
I brought this back from the farm where they grow the tiny ads:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic