Is Scala strongly typed?

  • Is Scala strongly typed? Do you have an example of how this is reflected in a language type system? Does Scala provide replication options? Does it allow you to force?

  • Does Scala have polytypes like ML?

Thank!

+4
source share
1 answer
  • Yes .

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. .

  1. , ML. this, () "generics", .

    • : : def identity[A](x: A): A = x
    • : : trait Option[+A] { def get: A }
+5

All Articles