Due to the strong text input, it doesn’t allow you to "type by type", as I understand that it is used in C. However, you have subtyping, so you can safely use the type value Awhere the type value is requested Bif A <: B( Ais a subtype or more specific than B).
a.asInstanceOf[B], , A B, , JVM, , , .
, "", :
// ordinary type
trait Foo {
def bar: Int
}
// structural type
type Bar = Any {
def bar: Int
}
def test(b: Bar) = b.bar
test(new Foo { val bar = 1234 }) // allowed
, Scala. , , .
, Dynamic trait. .
, ML. this, () "generics", .
- : :
def identity[A](x: A): A = x - : :
trait Option[+A] { def get: A }