Give the following to methods:
def beCool[T <: S](args:Array[T]) = {}
def beCool(args:Array[T forSome {type T <:S}]) = {}
Are they equivalent? Can you give me some examples when should prefer which?
You would need the first one, i think, whenever you need access to T
. The simplest example is returning an element of args:
def beCool(args: Array[T forSome { type T }]): T = args.head // --> not found: type T
def beCool[T](args: Array[T]): T = args.head // ok
the inexistance of an accessible type T
in the first one is more apparent when you use the wildcard:
def beCool(args: Array[_ <: S]) = ???
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With