groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fernando Ariel Niwes Naufal <ferna...@soluciones3f.com.ar>
Subject Inheritance when implementing traits at runtime
Date Fri, 30 Oct 2015 19:46:03 GMT
I expect the following script to pass all asserts

trait Greetable {
>     def  greeting() { "Hello!" }
> }
> class RegularPerson {}
> class VerySpecialPerson implements Greetable {
>     def greeting() { "Whazzup?" }
> }
> class SpecialPerson {
>     def greeting() { "Pleased to meet you" }
> }
> assert (new RegularPerson() as Greetable).greeting() == "Hello!"
> assert (new VerySpecialPerson() as Greetable).greeting() == "Whazzup?"
> assert (new SpecialPerson() as Greetable).greeting() == "Pleased to meet
> you"


But the last assert is not passing. Instead the result is hello!
It seems to me that inheritance does not works when using Traits at runtime.

Is it the expected behaviour? Is there a workaround?

Mime
View raw message