当前位置: 首页 > news >正文

南通网站建设知识餐饮营销案例100例

南通网站建设知识,餐饮营销案例100例,导航网站优化,网站别人帮做的要注意什么2019独角兽企业重金招聘Python工程师标准>>> 简单的 // protocol // 搞不懂为嘛不使用Flier<T>,而要多使用一个关键字associatedtype // 注: associatedtype是swift2.2新引入的关键字, 先前为typealias protocol Flier {associatedtype Tfunc flyWith(f: T)fu…

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

简单的

// protocol
// 搞不懂为嘛不使用Flier<T>,而要多使用一个关键字associatedtype
// 注: associatedtype是swift2.2新引入的关键字, 先前为typealias
protocol Flier {associatedtype Tfunc flyWith(f: T)func mateWith(f: T)func shitWith(f: Self) //Self表示将要实现这个接口的那个`类`的类型}
// 实现接口
class Bird: Flier {func flyWith(f: String) {}func mateWith(f: String) {}func shitWith(f: Bird) {}
}// 函数
func takeAndReturn<T>(t: T) -> T {return t
}takeAndReturn("hello")
takeANdReturn(2)// 结构体
struct HolderOfTwoSame<T> {var v1: Tvar v2: T
}
HolderOfTwoSame(v1: "hello", v2: "world")// 类
class Animal<T> {func playWith(t: T) {print("I am playing with: \(t)")}
}// 继承自指定了具体的泛型类型的Animal
class Dog: Animal<String> {}// 继承自泛型的Animal
class AnotherDog<T>: Animal<T> {override func playWith(t: T) {print("I played with: \(t)")}
}var animal = Animal<Int>()
animal.playWith(2)var d = Dog();
d.playWith("only string allowed here")var dd = AnotherDog<String>()
dd.playWith("xiaohua")

多个泛型参数

// protocol
// 搞不懂为嘛不使用Flier<A,B>,而要多使用一个关键字associatedtype?
protocol Flier {associatedtype Aassociatedtype Bfunc flyWith(f: A)func mateWith(f: B)func shitWith(f: Self) //Self表示将要实现这个接口的那个`类`的类型}class Bird: Flier {func flyWith(f: String) {}func mateWith(f: String) {}func shitWith(f: Bird) {}
}// func
func takeAndReturn<A,B>(v1: A, v2: B) -> (A,B) {return (v1, v2)
}takeAndReturn("hello", v2: 2)// struct
struct HolderOfTwoType<A, B> {var v1: Avar v2: B
}
HolderOfTwoType(v1: "hello", v2: "world")// class
class Animal<A,B> {func playWith(t: A, and: B) {print("I am playing with: \(t) and \(and)")}
}class Dog: Animal<String, Int> {}var animal = Animal<Int, String>()
animal.playWith(2, and: "Alice")var d = Dog();
d.playWith("only string allowed here", and: 3)

带类型约束的(protocol)

// 第一版
// protocol
protocol Flier {func flyWith(f: Flier)}class Bird: Flier {// 这里只能和protocol保持一致,声明为Flier,// 声明为Bird就会报错, (怎么能在这里定义成Bird, 见下面)func flyWith(f: Flier) {}
}class ButterFly: Flier{func flyWith(f: Flier){}
}var b1 = Bird()
var b2 = ButterFly()
b1.flyWith(b2)// 以下是第二版
// protocol
protocol SuperFlier {}
protocol Flier: SuperFlier {// error: type may not reference itself as a requirement// associatedtype T: Flierassociatedtype T: SuperFlier// 可以用一个类型为Flier的占位符放在这里// 但是蛋疼的是, 不能使用接口自身做为占位符// 所以这里定义了一个什么都不干的SuperFlier以此满足compiler的要求func flyWith(f: T)}class Bird: Flier {// 然后就可以在这里使用Birdfunc flyWith(f: Bird) {}
}var b1 = Bird()
b1.flyWith(b1)

带类型约束的(func)


// 出现了Self或associatedtype关键字的protocol叫做generic protocol
// generic protocol不能直接放在参数列表中, 只能做为类型约束(出现在尖括号里)
protocol Flier {associatedtype Tfunc flyWith(f: T)}// 注意这里的Bird并没有实现该generic protocol, 只是使用了(依赖)Flier
class Bird{// error: protocol 'Flier' can only be used as a generic constraint because it has Self or associated type requirements//func flyWith(f: Flier) {}// 上面这行代码出错, 应该改为func flyWith<T: Flier>(f: T) {}}// eg2: 函数体中的小于号要求这里的泛型参数必须是Comparable类型的
func myMin<T: Comparable>(things: T...) -> T {var minimum = things[0]for ix in 1..<things.count {if things[ix] < minimum {minimum = things[ix]}}return minimum
}

待续
阅读[What do you really know about typealias and associatedtype?]

在实现中指定泛型类型的几种方式
 

// 接口如下
protocol IAnimal {associatedtype T = Double // 其中 = Double是指定它的默认实现类型, 可以去掉func playWith(t: T)
}class Cat : IAnimal {// 1. 通过typealias指定associatedtype的具体类型typealias T = Stringfunc playWith(t: T) {print("I played with: \(t)")}}// 2. 通过尖括号指定associatedtype的具体类型
class AnotherCat<T> : IAnimal {func playWith(t: T) {print("I played with: \(t)")}}// 3. 通过尖括号指定associatedtype的具体类型(带类型约束)
class YetAnotherCat<T: IAnimal> : IAnimal {func playWith(t: T) {print("I played with: \(t)")}}var cat1 = Cat()
cat1.playWith("meow")var cat2 = AnotherCat<Int>()
cat2.playWith(2)var cat3 = YetAnotherCat<Cat>()
cat3.playWith(cat1)

待续

转载于:https://my.oschina.net/uniquejava/blog/683774

http://www.lbrq.cn/news/2366137.html

相关文章:

  • python官网下载安装黄山seo排名优化技术
  • 免费做网站怎么做网站619总裁班课程培训
  • 简述网站建设的标准智能建站网站模板
  • 网站备案 关闭今天的国内新闻
  • 门户网站建设重要性注册网站域名
  • 网站制作的趋势搜索引擎案例分析结论
  • 沈阳市 建委 网站普通话的顺口溜6句
  • 南海网官网seo工作是什么意思
  • 怎么做网站推广的步骤搜索引擎优化期末考试答案
  • 做简单的动态网站教程网站建站哪家公司好
  • 如何建立网站站点超链接友情外链查询
  • 河南网站建设公司 政府北京seo专业团队
  • 山东聊城建设局网站智能建站系统
  • 淘宝网站建设哪个类目seo优化外包
  • 做网站的过程网络推广员的前景
  • 惠州做网站开发网络营销渠道名词解释
  • 天津怎么建立企业网站seo搜索引擎优化论文
  • 黄山网络推广公司宁波seo如何做推广平台
  • 网站推广 教程北京疫情最新消息
  • 网站制作最新技术的百度品牌专区怎么收费
  • 长沙网站建设团队创建网址快捷方式
  • app和网站趋势药品销售推广方案
  • wordpress beginningseo入门课程
  • 酒店网站建设策划方案东莞做网站的公司有哪些
  • 做民宿房东怎样上网站卖房黑帽seo是作弊手法
  • 手机网站建设要多少钱南宁seo团队哪家好
  • 做欧美市场的网站厦门人才网官网
  • wordpress投稿者权限一键seo提交收录
  • 花生壳做网站需要备案爱奇艺科技有限公司
  • 青岛电商网站建设seo优化关键词分类
  • 聚类算法原理与应用(一):K-means聚类算法原理
  • Python包测试全攻略:从单元测试到持续集成
  • 人工智能之数学基础:神经网络之多样本矩阵参数求导
  • Git问题排查与故障解决详解
  • Python中的列表list、元组(笔记)
  • AWS IAM 最佳安全实践通用指南