Groovy Bar & Grill

February 26, 2007

Groovy Principle of Least Surprise Violation?

Filed under: Groovy Bar — jawild59 @ 9:21 pm

Anyone else surprised this code works?

class Book {
private title
}

def book = new Book()
book.title = 'Principle of Least Surprise'
assert book.title == 'Principle of Least Surprise'

Since title is private, shouldn’t I have to access it via getters and setters?

3 Comments »

  1. See http://jira.codehaus.org/browse/GROOVY-1591.

    Comment by Jeff Brown — February 28, 2007 @ 1:17 pm

  2. At least it’s recognized as critical

    Comment by Jeff W. — February 28, 2007 @ 8:18 pm

  3. Read page 70 in “Groovy Recipies”; “Gotcha: Groovy Ignores the Private Modifier

    Comment by stigl — June 20, 2008 @ 2:03 am


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.