t31321
t31321

Reputation: 773

grails def vs Object vs Void

what is the difference between these 3?

def search(String id) {
 //code
}

Object search(String id) {
 //code
}

void search(String id) {
 //code
}

specially between def and Object.

Upvotes: 11

Views: 8278

Answers (1)

injecteer
injecteer

Reputation: 20699

def is an alias for Object, so the first 2 signatures are identical.

the difference between the 1st two and the 3rd is, that you can return null or an instance of any class from the 1 and 2, whereas you can return only null from the 3rd one.

Upvotes: 19

Related Questions