groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Owen Rubel <oru...@gmail.com>
Subject Re: what's the difference?
Date Fri, 07 Aug 2015 15:24:32 GMT
To follow up on what Soren said...

The first one is a 'convenience method'; it's provided as a shortcut to
provide a simple and fast way to output.

The second is the long way of doing it and provides additional
functionality.

Owen Rubel
415-971-0976
orubel@gmail.com

On Fri, Aug 7, 2015 at 4:30 AM, Søren Berg Glasius <soeren@glasius.dk>
wrote:

> That's because it's two different ways of doing the same thing. The first
> is just more compact, and does not give you access to the reader, where as
> the second gives you access to the reader and allows you to do various
> things with it.
>
>
> Best regards / Med venlig hilsen,
> Søren Berg Glasius
>
> Hedevej 1, Gl. Rye, 8680 Ry, Denmark
> Mobile: +45 40 44 91 88, Skype: sbglasius
> --- Press ESC once to quit - twice to save the changes.
>
> On 7 August 2015 at 12:53, Mauro Sanna <mrsanna1@gmail.com> wrote:
>
>> It's not clear to me what's the difference between:
>>
>> file1.eachLine() { println it }
>>
>> and
>>
>> file1.withReader { reader ->
>>     while ((line = reader.readLine()) != null) {
>>         println line
>>     }
>> }
>>
>> the output is the same.
>> Thank you.
>>
>
>

Mime
View raw message