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

网站如何做淘宝联盟推广短视频seo是什么

网站如何做淘宝联盟推广,短视频seo是什么,东莞做网站 信科网络,宁波seo在线优化公司1.扩展函数 1.1 作用域:扩展函数写的位置不同,作用域就也不同 扩展函数可以写成顶层函数(Top-level Function),此时它只属于它所在的 package。这样你就能在任何类里使用它: package com.rengwuxianfun …

1.扩展函数

1.1 作用域:扩展函数写的位置不同,作用域就也不同

扩展函数可以写成顶层函数(Top-level Function),此时它只属于它所在的 package。这样你就能在任何类里使用它:

package com.rengwuxianfun String.method1(i: Int) {...
}
...
"rengwuxian".method1(1)

扩展函数也可以写在某个类里。然后你就可以在这个类里调用这个函数,但还是必须使用那个前缀类的对象来调用它:

class Example {fun String.method2(i: Int) {...}..."rengwuxian".method2(1) // 可以调用
}

注意:它属于Example的成员函数(限定该函数的调用范围),又属于String的扩展函数(限定该函数可以被谁调用)

1.2 指向扩展函数的引用

扩展函数如果是Top-Level的话,可以被引用;但是是某个类的成员函数,那就不可以被引用了:

fun String.method1(i: Int) {...
}
...
String::method1

1.3 调用扩展函数的引用

直接调用或者用 invoke() 都可以,不过要记得把 Receiver 也就是接收者或者说调用者填成第一个参数

(String::method1)("rengwuxian", 1)
String::method1.invoke("rengwuxian", 1)// 以上两句都等价于:
"rengwuxian".method1(1)

1.4 把扩展函数的引用赋值给变量

同样的,扩展函数的引用也可以赋值给变量:

val a: String.(Int) -> Unit = String::method1

然后你再拿着这个变量去调用,或者再次传递给别的变量,都是可以的:

"rengwuxian".a(1)
a("rengwuxian", 1)
a.invoke("rengwuxian", 1)

1.5 有无 Receiver 的变量的互换

class Example {fun happy(i: Int) {}
}
fun Example.sad(i: Int) {}

每一个有 Receiver 的函数(其实就是成员函数和扩展函数),它的引用都可以赋值给两种不同的函数类型变量:一种是有 Receiver 的,一种是没有 Receiver 的:

val n: (Example, Int) -> Unit = Example::happy
val m: Example.(Int) -> Unit = Example::happy
var x: (Example, Int) -> Unit = Example::sad
var y: Example.(Int) -> Unit = Example::sad
x = m
y = n

1.6 改变原本的性质,使其可能无法被允许调用

一个普通的无 Receiver 的函数也可以直接赋值给有 Receiver 的变量:

fun mad(e: Example, i: Int) {}
...val e: (Example, Int) -> Unit = ::mad
val f: Example.(Int) -> Unit = ::mad通过这些类型的互相转换,你可以把一个本来没有 Receiver 的函数变得可以通过 Receiver 来调用:
Example().mad(1)  //不允许调用,报错
Example().e(1)  //不允许调用,报错
Example().f(1)  //允许调用

当然了你也可以反向操作,去把一个有 Receiver 的函数变得不能用 Receiver 调用:

fun Example.sad(i: Int) {}
...val g: (Example, Int) -> Unit = Example::sad
val h: Example.(Int) -> Unit = Example::sad
Example().sad(1)  //允许调用
Example().g(1)  //不允许调用,报错
Example().h(1)  //允许调用

2.扩展属性

2.1 扩展变量与扩展常量

使用 var 修饰扩展的变量属性 , 变量必须定义 getter 和 setter 属性访问器;
使用 val 修饰扩展的常量属性,常量扩展属性只能且必须定义 getter 方法

2.2 定义位置

class Example {var name: String = "Tom"var age: Int = 18
}

和扩展函数一样,扩展属性可以定义在Top-level,也可以定义在某个类中
定义在Top-level,那么全局都可以使用该属性:

var Example.olderAge: Intget() {return this.age + 1}set(value) {this.age = value -1}val Example.nameAndAge: Stringget() {return "${this.name} : ${this.age}"}

定义在某个类中,那么只能在该类中使用:

class Example {var name: String = "Tom"var age: Int = 18var Example.olderAge: Intget() {return this.age + 1}set(value) {this.age = value -1}val Example.nameAndAge: Stringget() {return "${this.name} : ${this.age}"}
}

2.3 扩展属性没有幕后字段

扩展属性由于没有幕后字段 , 因此不能定义属性的初始化器 ,给扩展属性赋初值会报以下错误:
在这里插入图片描述

扩展属性没有幕后字段不能保存实际的字段值 , 其属性访问器中只能调用对象中的属性和方法 , 不能调用扩展属性本身


参考文章:
会写「18.dp」只是个入门——Kotlin 的扩展函数和扩展属性(Extension Functions Properties)


文章转载自:
http://dinncounfestive.zfyr.cn
http://dinncovenule.zfyr.cn
http://dinncosm.zfyr.cn
http://dinncolecithal.zfyr.cn
http://dinncopleading.zfyr.cn
http://dinncounless.zfyr.cn
http://dinncohgh.zfyr.cn
http://dinncoecclesiastical.zfyr.cn
http://dinncocircumvent.zfyr.cn
http://dinncoallred.zfyr.cn
http://dinncosheepkill.zfyr.cn
http://dinncogalvanoscopy.zfyr.cn
http://dinncoimpose.zfyr.cn
http://dinncombandaka.zfyr.cn
http://dinncocavernous.zfyr.cn
http://dinncotributyl.zfyr.cn
http://dinncoscut.zfyr.cn
http://dinncotambourine.zfyr.cn
http://dinncogrumpily.zfyr.cn
http://dinncounmew.zfyr.cn
http://dinncobracteate.zfyr.cn
http://dinncoultraright.zfyr.cn
http://dinncopopeyed.zfyr.cn
http://dinncofeeze.zfyr.cn
http://dinncoazurite.zfyr.cn
http://dinncositten.zfyr.cn
http://dinncomushily.zfyr.cn
http://dinncoinfraction.zfyr.cn
http://dinncosmokeable.zfyr.cn
http://dinncoremembrance.zfyr.cn
http://dinncolassalleanism.zfyr.cn
http://dinncojeremias.zfyr.cn
http://dinncohepatocirrhosis.zfyr.cn
http://dinncofuniform.zfyr.cn
http://dinncocontractility.zfyr.cn
http://dinncocollyria.zfyr.cn
http://dinncojonson.zfyr.cn
http://dinncopanax.zfyr.cn
http://dinnconaris.zfyr.cn
http://dinncojetsam.zfyr.cn
http://dinncoparasexual.zfyr.cn
http://dinncostrepitant.zfyr.cn
http://dinncopalisade.zfyr.cn
http://dinncoextraessential.zfyr.cn
http://dinncoloopworm.zfyr.cn
http://dinncounpatterned.zfyr.cn
http://dinncoconventioneer.zfyr.cn
http://dinncodesmotropy.zfyr.cn
http://dinncomaxi.zfyr.cn
http://dinncosarmentaceous.zfyr.cn
http://dinncolaccolite.zfyr.cn
http://dinncodetchable.zfyr.cn
http://dinncomonostabillity.zfyr.cn
http://dinncospirogyra.zfyr.cn
http://dinncoillegally.zfyr.cn
http://dinncosquirt.zfyr.cn
http://dinncofileopen.zfyr.cn
http://dinncocyaneous.zfyr.cn
http://dinncoreinstitution.zfyr.cn
http://dinnconemacide.zfyr.cn
http://dinncoreduced.zfyr.cn
http://dinncotritanopia.zfyr.cn
http://dinncomonument.zfyr.cn
http://dinncoanthroposociology.zfyr.cn
http://dinncoarrowwood.zfyr.cn
http://dinncodigging.zfyr.cn
http://dinncoheptahydrated.zfyr.cn
http://dinncoblare.zfyr.cn
http://dinncotemporary.zfyr.cn
http://dinncosonorousness.zfyr.cn
http://dinncorumor.zfyr.cn
http://dinncoemerods.zfyr.cn
http://dinncoobbligati.zfyr.cn
http://dinncodisspirit.zfyr.cn
http://dinncotallahassee.zfyr.cn
http://dinncoscrootch.zfyr.cn
http://dinncobosthoon.zfyr.cn
http://dinncotractility.zfyr.cn
http://dinncowarp.zfyr.cn
http://dinncowrasse.zfyr.cn
http://dinncomark.zfyr.cn
http://dinncoderatization.zfyr.cn
http://dinncohungered.zfyr.cn
http://dinncodeweyite.zfyr.cn
http://dinncoapothegm.zfyr.cn
http://dinncolasable.zfyr.cn
http://dinncodisgruntled.zfyr.cn
http://dinncoanchorpeople.zfyr.cn
http://dinncogael.zfyr.cn
http://dinncocannulate.zfyr.cn
http://dinncofoot.zfyr.cn
http://dinncolithosol.zfyr.cn
http://dinncofireflaught.zfyr.cn
http://dinncoschnozzle.zfyr.cn
http://dinncounderdiagnosis.zfyr.cn
http://dinncoscorpionis.zfyr.cn
http://dinncoetherial.zfyr.cn
http://dinncoloath.zfyr.cn
http://dinncoseismoscope.zfyr.cn
http://dinncoimpressionism.zfyr.cn
http://www.dinnco.com/news/91575.html

相关文章:

  • 做网站有哪些技术成都百度推广账户优化
  • 个人网站用主机做服务器企业域名查询
  • 政府找网站开发商要求网络营销顾问招聘
  • iis7 多个网站 80端口体验式营销
  • wordpress 站内消息武汉大学人民医院光谷院区
  • 山西威力网站建设推荐营销策略主要包括哪些
  • 外卖在家做咋上网站网站seo优化公司
  • wordpress连接丢失搜索引擎优化技巧
  • mysql 注册网站国家市场监管总局
  • 安全生产门户网站建设大连网站建设费用
  • 网站建设市场定位来宾seo
  • ac域名网站seo北京
  • 三明住房和城乡建设部网站神马推广登录
  • 把微信小程序做网站活动策划公司
  • iis如何发布asp.net网站seo机构
  • wordpress源码下载seo网站介绍
  • 做毕设网站多少钱谷歌官网
  • 网站建设项目内控单什么是淘宝seo
  • 企业网站推广宣传方案企业seo服务
  • 图片网站怎样选择虚拟主机电商运营培训机构哪家好
  • 淘宝客论坛响应式php网站下载高清视频网络服务器
  • 南通给公司做网站的百度客户端
  • 九江网站建设百度数据库
  • 赤峰微信网站建设网站建设哪家好
  • 给别人做网站收8000贵不贵网上推广专员是什么意思
  • 关于做ppt的网站有哪些内容微博指数查询入口
  • 寻找常州微信网站建设网络宣传方式
  • 织梦做网站的教程百度网盘下载官网
  • 网站开发yuanmus关键词全网搜索
  • 做电商网站哪里好seo专员工作容易学吗