What is the use of “use” keyword/method in groovy?

I read use keyword in Groovy. But could not come out with, for what it has been exactly been used. And i also come with category classes, under this topic,what is that too? And from, Groovy In Action

class StringCalculationCategory {
  static def plus(String self, String operand) {
    try {
      return self.toInteger() + operand.toInteger()
    } catch (NumberFormatException fallback) {
      return (self << operand).toString()
    }
  }
}

use (StringCalculationCategory) {
  assert 1 == '1' + '0'
  assert 2 == '1' + '1'
  assert 'x1' == 'x' + '1'
}

With the above code, can anyone say what is the use of use keyword in groovy? And also what the above code does?

23
задан Michal Kordas 16 April 2015 в 08:33
поделиться