Any thoughts on how a Scala trait’s method can become a default
method? I didn’t find very much documentation on this. My aim is for Java programs to avoid having to provide an implementation of a given trait.
To expand, given the following trait:
trait Provider[T <: SecretStore] {
def acquireSecretStore(config: Config)(implicit mat: Materializer, system: ActorSystem): T
}
I’m assuming that there’s no default
method given that there’s no implementation. Here’s the javap
output to confirm:
public interface com.github.huntc.streambed.identity.SecretStore$Provider<T extends com.github.huntc.streambed.identity.SecretStore> {
public abstract T acquireSecretStore(com.typesafe.config.Config, akka.stream.Materializer, akka.actor.ActorSystem);
}
If I then provide an implementation:
trait Provider[T <: SecretStore] {
def acquireSecretStore(config: Config)(implicit mat: Materializer, system: ActorSystem): T =
doAcquireSecretStore(config)
def doAcquireSecretStore(config: Config)(implicit mat: Materializer, system: ActorSystem): T
}
My, perhaps unreasonable, expectation is that acquireSecretStore
will become a default
method. Unfortunately not as per the following javap
output:
public interface com.github.huntc.streambed.identity.SecretStore$Provider<T extends com.github.huntc.streambed.identity.SecretStore> {
public static com.github.huntc.streambed.identity.SecretStore acquireSecretStore$(com.github.huntc.streambed.identity.SecretStore$Provider, com.typesafe.config.Config, akka.stream.Materializer, akka.actor.ActorSystem);
public T acquireSecretStore(com.typesafe.config.Config, akka.stream.Materializer, akka.actor.ActorSystem);
public abstract T doAcquireSecretStore(com.typesafe.config.Config, akka.stream.Materializer, akka.actor.ActorSystem);
public static void $init$(com.github.huntc.streambed.identity.SecretStore$Provider);
}
Thanks for any guidance.