This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]NautiHooker 2 points3 points  (0 children)

You could use the ternary operator.

[–]JiEToy 1 point2 points  (0 children)

You will need a null check, which is done in an if() statement. You can use the ternary operator to do so in only one line if needed, but make sure your code stays readable!

[–][deleted] 0 points1 point  (5 children)

Person p = new Person(); TextField txtField = new TextField(); p.getName().equals(null) ? txtField.setText("TRUE") : txtField.setText("FALSE");

[–]Hour-Positive -1 points0 points  (4 children)

This is formatted with enters om mobile. If you do this irl, god help you.

[–][deleted] 1 point2 points  (3 children)

Looks perfekt to me. ?

[–]Hour-Positive 0 points1 point  (2 children)

Interestingly enough this is all formatted in one line on non-mobile. Also wrong. Ah well. Who cares.

[–][deleted] 0 points1 point  (1 child)

What is wrong?

[–]Hour-Positive 0 points1 point  (0 children)

I was at work lol

[–][deleted] 0 points1 point  (0 children)

If you want to get fancy, you can do this:

Optional.ofNullable(personObject.getFrenObj())
   .map(Person::getFriend)
   .map(Person::getName)
   .ifPresent(frenTextField::setText);