Skip to content

Instantly share code, notes, and snippets.

/TestTraitEx2.groovy
Created Apr 23, 2014

Embed
What would you like to do?
// 簡單的 trait
trait SwimmingAbility {
def swim() {
println "swimming.."
}
}
// 取得類別資訊的 trait
trait FlyingAbility {
def fly() {
println "${this.class.name} is flying.."
}
}
// 使用多個 trait
class Duck
implements SwimmingAbility, FlyingAbility
{
}
// example 2
def duck = new Duck()
duck.swim() // 使用 SwimmingAbility.swim()
duck.fly() // 使用 FlyingAbility.fly()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.