| Author |
EL value for unknown variables. Math and logical.
|
Cristiano Sganzerla
Ranch Hand
Joined: Jan 14, 2006
Posts: 44
|
|
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
|
SCJP 1.4 - SCWCD 1.4
|
 |
Carl Wauters
Greenhorn
Joined: Aug 02, 2007
Posts: 19
|
|
- 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
|
SCJP 5.0, SCWCD 1.4, SCBCD 5.0, SCJD, SCDJWS 5.0, SCEA/OCMJEA 5
|
 |
Cristiano Sganzerla
Ranch Hand
Joined: Jan 14, 2006
Posts: 44
|
|
|
Thanks Carl !!!
|
 |
 |
|
|
subject: EL value for unknown variables. Math and logical.
|
|
|