Say you have a method:
boolean test() { return true; }
Would it ever be a good idea to use metaprogramming to change it to return a String:
String test() {return "test"}
I think using metaprogramming for that is confusing and should be avoided since it changes the public interface that calling code expects. Does an开发者_如何学Cyone have an example of when it would be a good idea?
I think if you are dynamically returning different types it would make more sense to just type the method return as def
such as:
def test() {
if (something) {
return true
} else {
return 'test'
}
}
So to answer your question, no I do not think it would ever be a good idea. :)
精彩评论