Created
January 28, 2016 04:47
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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