Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Won't Fix
-
Affects Version/s: 1.0
-
Fix Version/s: 1.1-rc-1
-
Component/s: groovy-jdk
-
Labels:None
-
Number of attachments :
Description
Currently if you want to do something with a character stream i.e. Reader its common to provide multiple methods.
doSomething(Reader)
doSoemthing(File)
doSomething(URL)
doSomething(String)
And the File, URL, String methods will do extra operations to create a reader before calling doSomething(Reader).
The other option is to only have the reader method and make the caller perform those operations.
It would be nice if groovy could mash an object into another type to fit the parameters. i.e. If you called a method taking a Reader and you passed a File, it would create a new FileReader for you.
Maybe it looks for a method called toReader on the parameter?
Obviously this can create problems, like oversimplifying character encoding issues with readers etc. And may lead to bad APIs when called from Java. But its a timesaving feature. Any thoughts.
Interesting - might be worth adding a helper method toReader() somewhere; not sure if it should go on Object or if it should be a helper method elsewhere?