2

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?

1 Answers1

2

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
Lee
  • 142,018
  • 20
  • 234
  • 287
  • Thank you! Lots of scala concepts are really nice :) I need to get more into it – hotzenplotz Jul 07 '15 at 10:30
  • I have just looked with javap at the bytecode - it looks like Scala is doing this with checkcast instruction whenever additional types are used. In this example B. Poor compiler has to do many things in scala. – hotzenplotz Jul 07 '15 at 10:48