tags:

views:

63

answers:

2

In a groovy tutorial, I encountered the following code:

class DateTagLib {
  def thisYear = {
    out << Calendar.getInstance().get(Calendar.YEAR)
  }
}

I don't know what the << means, and I'm having no luck with google.

Edit: I now know that << sometimes is a bit shift. But what does it mean here?

A: 

It's used for bit-shift operations. More info:

http://groovy.codehaus.org/Bitwise+Operations

Will
How does that make any sense in this context?
FarmBoy
@FarmBoy, welcome to the pain that is operator overloading...
Carl Norum
Sorry FB, I didn't spot your example code when I first read this. Please ignore my post.
Will
+7  A: 

In groovy, the bitwise operators can be overridden with the leftShift (<<) and rightShift (>>) methods defined on the class. it's idiomatic groovy to use the leftShift method for append actions on strings, buffers, streams, arrays, etc and thats what you're seeing here.

http://groovy.codehaus.org/groovy-jdk/java/io/OutputStream.html

Youre looking at a grails tag lib, so out represents the page that's being rendered. The results off this taglib will be added to the output buffer that will be rendered to the client.

Ted Naleid