Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is this operator called and what is it used for <=>

I recently came across this magical operator when digging into Groovy: <=>

Groovy has really made me happy with elvis operators ?. and ?: which I use constantly now and very much wish were in Java. With this new operator, I have only found this reference. It seems to make comparators much easier. My question is how does it handle null values and how does it compare non Comparable object. Does this operator have a name, I couldn't find it Googling.

like image 567
Scott Avatar asked Mar 16 '11 06:03

Scott


People also ask

What is operator in typescript?

An Operator is a symbol which operates on a value or data. It represents a specific action on working with data. The data on which operators operates is called operand. It can be used with one or more than one values to produce a single value.

What is the operator is called?

What is Operator? Simple answer can be given using expression 4 + 5 is equal to 9. Here 4 and 5 are called operands and + is called operator.

What is this operator used for?

Arithmetic Operators are used to perform mathematical calculations. Assignment Operators are used to assign a value to a property or variable. Assignment Operators can be numeric, date, system, time, or text. Comparison Operators are used to perform comparisons.

What is this == operator called?

Relational Operators == (Equal to)– This operator is used to check if both operands are equal. != (Not equal to)– Can check if both operands are not equal. >


2 Answers

You got a list of operators here. It is called the "Spaceship" operator. It handles null without problem.

like image 168
J-16 SDiZ Avatar answered Oct 01 '22 19:10

J-16 SDiZ


It's called the spaceship operator and is also commonly used for comparison in Ruby.

http://www.objectpartners.com/2010/02/08/the-groovy-spaceship-operator-explained/

like image 28
Brandon Avatar answered Oct 01 '22 19:10

Brandon