• 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

EL value for unknown variables. Math and logical.

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was working with EL to see the different behaviors when dealing with math and logical operators.

HFSJ stated:

Logical operators, unknown variable receives 'false'
Math operators, unknown variable receives 0

The first problem
How is this evaluated, since foo isnt known
Example:

${foo < 3} ---> false < 3 ??? What the hell is that ?

${!foo} ---> true = ok

${foo eq false} ---> false = why ???
${foo == false} ---> false = why ???

${'0' || '0'} ---> false - is it ok to use logical operators with string? Always evaluate to false ?

${0 || 0} ---> exception - Attempt to coerce a value of type "java.lang.Long" to Boolean

${'0' == 0} ---> true - Converts '0' to numeric.

I stated that if one of the variables is numerical, the other variable will be cast to numerical, even if it is a String, then the math or logical operator will be applyed.

I really dont know if these stupid questions will be done in the exam, since we are not talking about SCJP, but i was wondering how EL really works with these variations.

Thanks in advance
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- Considering your first problem: ${foo eq aValue} This will only return true when you compare foo to null.
- Considering your second problem: ${'0' || '0'} This will only return true when one of those strings is equal to 'true'


About casting: i'm not completely sure, but I guess you can compare Strings to Strings, numbers to numbers, booleans to booleans, booleans to Strings and numbers to Strings, but in the latter case, the String must be able to be converted to a number.

Hope this helps...

Regards,

Carl
 
Cristiano Sganzerla
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Carl !!!
 
    Bookmark Topic Watch Topic
  • New Topic