Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
开发者_JAVA百科 Improve this questionI just had a quick question about downloading files. I was reading this page:
http://groovy.codehaus.org/Simple+file+download+from+URL
Can someone explain what the difference is between the two ways explained on that page? (Aside from overriding the leftshift operator) Is there any significance for doing it one way or the other?
The former method is far cleaner and is what you would do in most cases.
The second is effectively enhancing the File object within the use closure. I can't see where it would be useful in this context, but say in your code you were often putting content from urls into files, or you had a dsl where you wanted to allow for that functionality, you could use categories to extend the file object.
Personally, I see the example as really just showing (a rather impractical) use for categories.
精彩评论