Issue Details (XML | Word | Printable)

Key: GROOVY-2162
Type: Improvement Improvement
Status: Closed Closed
Resolution: Duplicate
Priority: Minor Minor
Assignee: Paul King
Reporter: BarzilaiSpinak
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

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

Created: 03/Oct/07 01:41 PM   Updated: 09/Oct/07 11:15 PM   Resolved: 09/Oct/07 11:15 PM
Return to search
Component/s: groovy-jdk, parser
Affects Version/s: None
Fix Version/s: 1.1-rc-1

Time Tracking:
Not Specified


 Description  « Hide

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



Paul King added a comment - 09/Oct/07 11:15 PM

Duplicate of GROOVY-1737