Safe calls

The safe call can be written using the .?. It can be called when the reference holds a non-null value when the value holds a null reference then the null value will be returned:

val hash:TrackedHashTag? = TrackedHashTag(hashTag="java",queue="java")val queueString = hash?.queue

When the hash? holds null, the null value will be assigned to a queueString attribute. If the hash? has a valid reference, the queue attribute will be assigned to a queueString attribute.

Get Spring 5.0 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.