Groovy Operator Types Overview
Groovy supports a variety of operations and operators, including arithmetic operations, comparison operations, logical operations, and more.
Here are some common operations and operators in Groovy:
- Arithmetic Operations: Addition, subtraction, multiplication, division, modulo, etc.
def a = 10
def b = 5
def c = a + b // Arithmetic addition operation
def d = a - b // Arithmetic subtraction operation
def e = a * b // Arithmetic multiplication operation
def f = a / b // Arithmetic division operation
def g = a % b // Modulo (remainder) arithmetic operation
- Comparison Operations: Equality, inequality, greater than, less than, etc.
def x = 10
def y = 5
def result1 = x == y // Equality check
def result2 = x != y // Inequality check
def result3 = x > y // Greater than comparison
def result4 = x < y // Less than comparison
def result5 = x >= y // Greater than or equal to comparison
def result6 = x <= y // Less than or equal to comparison
- Logical Operations: AND, OR, NOT, etc.
def isAdult = true
def hasLicense = false
def canDrive = isAdult && hasLicense // Logical AND operation
def canDrink = isAdult || hasLicense // Logical OR operation
def cannotVote = !isAdult // Logical NOT operation
Please note that Groovy also supports bitwise operations, ternary operators, and other types of operations and operators.