mercredi 4 janvier 2017

How to write 'else if' the 'groovyish' way?

So I have a groovy method that really looks more like Java and I was hoping to figure out a good 'groovyish' way to rewrite this block:

String getStuff(obj1, obj2) {
  def response
  if(obj1 && obj2) {
    throw new RuntimeException('bleh')
  } else if(obj1) {
    response = firstMethod(obj1)
  } else if(obj2) {
    response = secondMethod(obj2)
  } else {
    response = thirdMethod()
  }
  JsonOutput.toJson(response)
}

Any ideas?

Aucun commentaire:

Enregistrer un commentaire