Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grails def vs Object vs Void

Tags:

groovy

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.

like image 831
t31321 Avatar asked Dec 20 '14 14:12

t31321


1 Answers

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.

like image 159
injecteer Avatar answered Oct 12 '22 13:10

injecteer