#Quick Question
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
ur msiunderstanding the problem
- you are accessing it, but the err is coming because
ifdemands a boolean value
- you frogot to return a value
string.isEmpty()
if (firstName.equals("John"))
if (firstName.isEmpty())
and so on
the thing inside the if must be a boolean, i.e. true or false
Or it could be a way to check if the first name is null?
then u need to write that expliciitly
We use: "firstName.isEmpty()"?
And if i do want to say if its not null, i do: ?
if (firstName != null) {}
Unlike C, you can't test the nullity of a reference directly... There's no truthiness until you have a boolean condition.
So the checking can also be done without making the strings of the class a boolean, which its awesome!
Yeah forgot about that!
In general i think when we run a IF statement, what we actually say is: "If the condition or not, then do that or else."
Yeah i forgot abt that a bit.
and if i do like this:
if (firstName != null && lastName != null) {}
It will still work?
sure
As it should mean: "If the first name and the last name is not null, then do that"
if (boolean && boolean) and that resolves to if (boolean) as well
Interesting man!
Thanks allot
I was doing a challenge from Modern java and got confused a bit when i saw it didn't work to check the names 😭
But ig from mistakes we learn