Last active
January 10, 2017 09:19
-
-
Save ukitaka/8a6cc48222c8a5f397fa5e9fb113c1bc to your computer and use it in GitHub Desktop.
型制約をつけると具体型が必要になる.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Creature { } | |
protocol Animal: Creature { } | |
struct Dog: Animal { } | |
struct Cat: Animal { } | |
// OK | |
class Hoge<A> { } | |
let hoge = Hoge<Animal>() // OK | |
// NG | |
// error: using 'Animal' as a concrete type conforming to protocol 'Creature' is not supported | |
class Fuga<A: Creature> { } | |
let fuga = Fuga<Animal>() // NG | |
// OK | |
class Piyo<A> { } | |
extension Piyo where A: Creature { } | |
let piyo = Piyo<Animal>() // OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment