Skip to content

Instantly share code, notes, and snippets.

@nobeans
Created January 28, 2016 04:47
Show Gist options
  • Save nobeans/4832bd98a0b62fb037c7 to your computer and use it in GitHub Desktop.
Save nobeans/4832bd98a0b62fb037c7 to your computer and use it in GitHub Desktop.
A private member in super trait cannot be accessed from sub trait (and sub class)
trait TraitA {
def propA = "AAA"
private privatePropA = "aaa"
def doA() {
propA + privatePropA
}
}
trait TraitB extends TraitA {
def propB = "BBB"
def doB() {
propA + propB
}
def doBWithPrivate() {
privatePropA + propB
}
}
class Hoge implements TraitB {
}
assert new Hoge().doA() == 'AAAaaa'
assert GroovyAssert.shouldFail(groovy.lang.MissingPropertyException) {
new Hoge().privatePropA
}.message == "No such property: privatePropA for class: Hoge"
assert new Hoge().doB() == 'AAABBB'
assert GroovyAssert.shouldFail(groovy.lang.MissingPropertyException) {
new Hoge().doBWithPrivate()
}.message == "No such property: privatePropA for class: Hoge"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment