Elvis operator : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

Elvis operator

Groovy has the ?: operator called the Elvis operator because it looks a bit like Elvis Presley’s hair. Java does not support it. It is helpful in dealing with values that might be null. It is a shorcut for a common piece of code to deal with null values. If the Elvis operator were introduced to Java:

// Instead of writing:
val = something != null ? something : defaultValue;

// you would write:  
val = something ?: defaultValue;

This page is posted
on the web at:

http://mindprod.com/jgloss/elvisoperator.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\elvisoperator.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[3.15.17.60]
You are visitor number