Generics Wild Card in Scala PRO

When defining a variable of a generic type we can use a wild card instead of specifying the exact secondary type the generic type uses.

object HelloSample
{
  def main(args:Array[String]):Unit =
  {
    val a:MyStack[SportCar] = new MyStack[SportCar];
    val b:MyStack[_ <: Car] = a;
  }
}

class Car

class SportCar extends Car

class MyStack[T]

The following video clip shows the execution of this code sample and explains it.

Share:

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Update cookies preferences