Search code examples
methodstypesbounded-typesstatic-language

multi bounded methods in a statically typed language?


Sorry the title is kinda wrong. Because I was thinking about method binding, when this question came up. Example with some pseudo code..

interface A
interface B

val z: A & B = [object of a class that implements A and B];

Is their any statically language that supports this feature?
-> Resolution of references to both types of z.
Or do I have some logic problems and it isn't possible?


Solution

  • You can do this in scala with traits:

    trait A
    trait B
    class Z extends A with B
    
    val z: A with B = new Z