grails - What would be the return type of this method in groovy? -


i have method such this:

def getinformation ()  {    return [true, "reason why"] } 

which i'm using this

def (isclear, reason) = getinformation() 

is there way define return type method better read when going through method?

the real return type of method object, since declared using 'def'. means can return anything, regardless of object you're returning.

the following code valid:

def getinformation ()  {       return "this information" } 

or

def getinformation ()  {       return 42 } 

but returntype of method hasn't changed.

the real question here is: why choose such approach? in opinion, following make things more clear:

result getinformation() {      return new result(success: true, reason: "why") } 

this make more clear caller, , thing you'd need create trivial class:

class result {      boolean success      string reason } 

now you've got defined api. never use def in method signature, because of problem you're facing here.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -