#Quick Question

1 messages · Page 1 of 1 (latest)

proper grove
#

Why in a class, it wont allow me to access the string of the firstname, even if the firstname is a string.

alpine shoreBOT
#

<@&987246399047479336> please have a look, thanks.

faint silo
rotund hemlock
faint silo
#

the issue is that what u wrote isnt a conditiion

#

if what?

#

if string makes no sense

rotund hemlock
#
  1. you frogot to return a value
faint silo
#

if string empty? if string John?

#

thats sth that works

#

but not if string

rotund hemlock
faint silo
#

if (firstName.equals("John"))

#

if (firstName.isEmpty())

#

and so on

#

the thing inside the if must be a boolean, i.e. true or false

proper grove
faint silo
#

then u need to write that expliciitly

proper grove
#

We use: "firstName.isEmpty()"?

faint silo
#

if (firstName == null)

#

dependiing on what u want to check

proper grove
faint silo
#

yes 👌

#

as long as java eventually gets if (boolean) its happy

pulsar canopy
#

Unlike C, you can't test the nullity of a reference directly... There's no truthiness until you have a boolean condition.

proper grove
# faint silo yes 👌

So the checking can also be done without making the strings of the class a boolean, which its awesome!

proper grove
#

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."

proper grove
faint silo
#

sure

proper grove
#

As it should mean: "If the first name and the last name is not null, then do that"

faint silo
#

if (boolean && boolean) and that resolves to if (boolean) as well

proper grove
#

Thanks allot

proper grove
# faint silo sure

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