Is it possible to limit the types that can implement a trait? Say for example, I have a type
interface Something { void foo() }
and sign
trait SomethingAbility { void bar() { println "bar" } }
Is there a way that I can only allow attribute implementation by classes that are of type Something , for example.
One option is to add an abstract method to the attribute
trait SomethingAbility { void bar() { println "bar" } abstract void foo() }
This means that this attribute cannot be implemented by the class if this class does not provide the foo() method, but this is not the same as a class of type Something
source share