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

New GDK method: Object[].contains()

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.8.5, 2.0-beta-2
    • 1.8.6, 2.0-beta-3
    • groovy-jdk
    • None

    Description

      We treat arrays as Lists in may respects. There are methods from List that have been grafted unto arrays however there is no contains() method which would come in handy in scenarios like the following one

      if(!arrayOfObjects.contains(element)) {
          arrayOfObjects << elements
      }
      

      One way to do it currently is this

      if( !(element in arrayOfObjects) ) {
          arrayOfObjects << elements
      }
      

      Notice the additional () around the expression

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            paulk Paul King
            aalmiray Andres Almiray
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment