Scala class to implement two Java Interfaces - how?
Posted
by puudeli
on Stack Overflow
See other posts from Stack Overflow
or by puudeli
Published on 2010-06-18T09:32:24Z
Indexed on
2010/06/18
9:43 UTC
Read the original article
Hit count: 306
Hi,
I have just started learning Scala and I'm now wondering how I could implement two different Java interfaces with one Scala class? Let's say I have the following interfaces written in Java
public interface EventRecorder {
public void abstract record(Event event);
}
public interface TransactionCapable {
public void abstract commit();
}
But a Scala class can extend only one class at a time. How can I have a Scala class that could fulfill both contracts? Do I have to map those interfaces into traits?
Note, my Scala classes would be used from Java as I am trying to inject new functionality written in Scala into an existing Java application. And the existing framework expects that both interface contracts are fulfilled.
© Stack Overflow or respective owner