I want to read a value from the session object which returns Object
type.
I know that the object has either true
/false
value.
I would like to convert that value into boolean
type. So I have the following code.
session.getAttribute("MyKeyValue"); // It returns Object type
Below throws an Exception.
boolean myBoolVal = Boolean.parseBoolean((String) session.getAttribute("MyKeyValue"));
Below works properly.
boolean myBoolVal = Boolean.parseBoolean(session.getAttribute("MyKeyValue").toString());
Actually, I don't understand why option 1 is not working ?