Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2162

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

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Duplicate
    • None
    • 1.1-rc-1
    • groovy-jdk, parser
    • None

    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

      Attachments

        Activity

          People

            paulk Paul King
            barspi Barzilai Spinak
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: