groovy

The unary negate "~" operator could work with any kind of object, not just numbers and strings

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Duplicate
  • Affects Version/s: None
  • Fix Version/s: 1.1-rc-1
  • Component/s: groovy-jdk, parser
  • Labels:
    None
  • Number of attachments :
    0

Description

Look at this piece of code

groovy> class A
groovy> { def negate() { return "denial!" }
groovy> }
groovy>
groovy> def a= new A()
groovy> println ~a

Exception thrown: groovy.lang.BitwiseNegateEvaluatingException: Cannot bitwise negate type A, value A@5b02a6
groovy.lang.BitwiseNegateEvaluatingException: Cannot bitwise negate type A, value A@5b02a6
at Script0.run(Script0:10)

It would be really useful if it would call negate() on any type of object. It would help especially in the creation of DSL's since we are in shortcut of unary prefix operators

Activity

Hide
Paul King added a comment -

Duplicate of GROOVY-1737

Show
Paul King added a comment - Duplicate of GROOVY-1737

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: