What is it? to groovy variables?

I saw in some groovy code:

trip.id?.encodeAsHTML()

What is the difference between using or not having "id ?."?

+3
source share
3 answers

It checks if the object is null or not. Using this, you can throw a nullpointer exception.

If you use it, you should use it for the entire object (for example: trip.id?.otherstuff?morestuff?.encodeAsHTML ()

+6
source

He called the "null-safe dereference operator." The difference is that if trip.idit is null, instead of throwing NullPointerException, it returns nullas a result of calling the method.

+4
source

Groovy . . Groovy .

+1

Source: https://habr.com/ru/post/1777429/


All Articles