The default type parameter in inheritance

Let's say I have the following classes:

class A[T] { ... }

abstract class B[T1,T2](t: T1)(implicit ev: A[T2]) {
... 
}

In some cases, when I inherit from B, the type for T2 is the same as for T1. Is there a way I can define my class so as not to explicitly state this?

Therefore, instead of doing:

class C extends B[String, String]("Some string") {
...
}

Can I have a compiler how to draw a conclusion, so I only need to write:

class C extends B("Some string") {
...
}
+4
source share
1 answer

I think a type alias should work:

type B1[T] = B[T, T]

class C extends B1("Some string") {
   ...
}
+2
source

Source: https://habr.com/ru/post/1672197/


All Articles