Hacker News new | past | comments | ask | show | jobs | submit login

This is essentially a Scala "self-type".

  trait InterfaceA

  trait InterfaceB { self: InterfaceA => }

  class A extends InterfaceA // compiles

  class B extends InterfaceB // does not compile

  class B extends InterfaceA with InterfaceB // compiles
"self" isn't a keyword, you can call it whatever you like.



Hah, now that is nice.

I forget what convoluted use case I wanted it for. I ended up solving it using composition instead (which is the right solution 99% of the time anyway. :) )

Still though, I love using interfaces as contracts, so I get frequently annoyed at how poorly my tools (limited to C++2003 right now) support doing such!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: