Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Let's have a look at another simple usage of @Delegate, for wrapping an existing class, delegating all calls to the delegate:

Code Block
class Photo {
       int width
       int height

class PhotoSelection {
       @Delegate Photo photo

       String title
       String caption

def photo = new Photo(width: 640, height: 480)
def selection = new PhotoSelection(title: "Groovy", caption: "Groovy", photo: photo)

assert selection.title == "Groovy"
assert selection.caption == "Groovy"

assert selection.width == 640
assert selection.height == 480