Declaring types that use generics
class A<T, E.> {
var obj : T?, obj2 : E?
func foo(foo : T, bar : E, baz : K) {
}
}
Declaring a variable of a type that uses generics
var a : A<String, Integer> = A<String, Integer>()
var b = A<String, Integer>()
var c = A<String>() // Missing generics are inferred as Object
Using functions that use generics that are not supplied by the enclosing class.
func foo(obj : A){
...
}
foo("Sam") // A is inferred as being String
Type restrictions can also be applied.
<T : ClassA, InterfaceA, InterfaceB>
The type used in place of T would then have to extend ClassA and implement the InterfaceA and InteferfaceB interfaces.
Declaring types that use generics
Declaring a variable of a type that uses generics
Using functions that use generics that are not supplied by the enclosing class.
Type restrictions can also be applied.
The type used in place of
Twould then have to extendClassAand implement theInterfaceAandInteferfaceBinterfaces.