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

String variants for take and drop

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.0.0-alpha-4, 2.5.5
    • groovy-jdk
    • None

    Description

      We have GString but not String variants for take and drop.

      @groovy.transform.CompileStatic
      def method() {
          assert 'Foo Bar'.drop(4).toLowerCase() == 'bar'
          assert 'Foo Bar'.take(3).toLowerCase() == 'foo'
      }
      
      method()
      

      You are required to add some superfluous .toString() calls otherwise you get the following errors:

      2 compilation errors:
      
      [Static type checking] - Cannot find matching method java.lang.CharSequence#toLowerCase(). Please check if the declared type is correct and if the method exists.
       at line: 3, column: 12
      
      [Static type checking] - Cannot find matching method java.lang.CharSequence#toLowerCase(). Please check if the declared type is correct and if the method exists.
       at line: 4, column: 12
      

      Attachments

        Activity

          People

            paulk Paul King
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: