Huang_Hai_Feng
Huang_Hai_Feng

Reputation: 287

What does T equals T mean in Generics

I'm studying apple's new language swift, and i looked at the Swift module,
and saw some generic classes have below statements:

extension ContiguousArray<T> : ArrayType {

    /// Construct an empty ContiguousArray
    init()
    init<S : Sequence where T == T>(_ s: S) 

    /* other statement skipped */
}  

I wondering What does the Where T == T mean?
I could not figure it out, Could anyone out there help me?

Upvotes: 4

Views: 351

Answers (1)

TheCodingArt
TheCodingArt

Reputation: 3429

T is a reference to any type. This allows you to dynamically set a type for something... like an Array. T == T is like saying typeof(Int) == typeof(Int) in obj c

Upvotes: 1

Related Questions