let's consider:
public class Text extends BinaryComparable
implements WritableComparable<BinaryComparable> {
We can see that Text is BinaryComparable.
Then, let's consider
@InterfaceAudience.Public
@InterfaceStability.Stable
public interface WritableComparable<T> extends Writable, Comparable<T> {
I have some class in Scala:
trait MyClass[A <: WritableComparable[A]] {
It is not possible to create
MyClass[Text] = new MyClass[Text]()
due to type mismatch. Why? After all, Text is BinaryComparable How to resolve it?
You can try to add one more type parameter
On contrary to
trait MyClass[A <: WritableComparable[_ >: A]]this doesn't produceillegal cyclic reference.Alternatively you can define bounds in
MyClassasYou can even exclude
Bwith existential type (as @user proposed)Such existential types will be deprecated in Scala 3
http://dotty.epfl.ch/docs/reference/dropped-features/existential-types.html