I saw in some groovy code:
trip.id?.encodeAsHTML()
What is the difference between using or not having "id ?."?
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 ()
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.
trip.id
NullPointerException
null
Groovy . . Groovy .
Source: https://habr.com/ru/post/1777429/More articles:How can I change the href anchors after clicking it? - javascriptWhy am I losing a new line character when loading text from a Java servlet in JTextPane? - javaProgramming without transitions - optimizationWhat does symmetry mean when building Real vs Imaginary Components FFT of the periodic time series - mathВызов Scala из Groovy: как обрабатывать разные типы коллекций? - scalaSpring validation: cannot convert from String to Date - springDatabase Synchronization Mirroring / Replication / Logging - sql-server-2008Can PHP be used inside an XML file? - xmlActiveMQ: starting a consumer without a broker - javaSQL Server Database Comparison Tool - databaseAll Articles