Kotlin 技术培训

Similar documents
Microsoft Word - 01.DOC

詞 彙 表 編 號 詞 彙 描 述 1 預 約 人 資 料 中 文 姓 名 英 文 姓 名 身 份 證 字 號 預 約 人 電 話 性 別 2 付 款 資 料 信 用 卡 別 信 用 卡 號 信 用 卡 有 效 日 期 3 住 房 條 件 入 住 日 期 退 房 日 期 人 數 房 間 數 量 入

OOP with Java 通知 Project 4: 4 月 19 日晚 9 点

untitled

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

OOP with Java 通知 Project 4: 5 月 2 日晚 9 点

EJB-Programming-4-cn.doc

06 01 action JavaScript action jquery jquery AJAX CSS jquery CSS jquery HTML CSS jquery.css() getter setter.css('backgroundcolor') jquery CSS b

OOP with Java 通知 Project 3: 3 月 29 日晚 9 点 4 月 1 日上课

Java

《大话设计模式》第一章

Microsoft Word - PHP7Ch01.docx

javaexample-02.pdf

Microsoft PowerPoint - string_kruse [兼容模式]

FY.DOC

(TestFailure) JUnit Framework AssertionFailedError JUnit Composite TestSuite Test TestSuite run() run() JUnit

RxJava

Chapter 9: Objects and Classes

基于CDIO一体化理念的课程教学大纲设计

无类继承.key

<4D F736F F F696E74202D20332D322E432B2BC3E6CFF2B6D4CFF3B3CCD0F2C9E8BCC6A1AAD6D8D4D8A1A2BCCCB3D0A1A2B6E0CCACBACDBEDBBACF2E707074>

IoC容器和Dependency Injection模式.doc

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

Microsoft PowerPoint - plan08.ppt

9, : Java 19., [4 ]. 3 Apla2Java Apla PAR,Apla2Java Apla Java.,Apla,,, 1. 1 Apla Apla A[J ] Get elem (set A) A J A B Intersection(set A,set B) A B A B

Java java.lang.math Java Java.util.Random : ArithmeticException int zero = 0; try { int i= 72 / zero ; }catch (ArithmeticException e ) { // } 0,

幻灯片 1

1.JasperReport ireport JasperReport ireport JDK JDK JDK JDK ant ant...6

建模与图形思考

Microsoft Word - ch04三校.doc

untitled

雲端 Cloud Computing 技術指南 運算 應用 平台與架構 10/04/15 11:55:46 INFO 10/04/15 11:55:53 INFO 10/04/15 11:55:56 INFO 10/04/15 11:56:05 INFO 10/04/15 11:56:07 INFO

新版 明解C++入門編

untitled

SDK 概要 使用 Maven 的用户可以从 Maven 库中搜索 "odps-sdk" 获取不同版本的 Java SDK: 包名 odps-sdk-core odps-sdk-commons odps-sdk-udf odps-sdk-mapred odps-sdk-graph 描述 ODPS 基

BOOL EnumWindows(WNDENUMPROC lparam); lpenumfunc, LPARAM (Native Interface) PowerBuilder PowerBuilder PBNI 2

主程式 : public class Main3Activity extends AppCompatActivity { ListView listview; // 先整理資料來源,listitem.xml 需要傳入三種資料 : 圖片 狗狗名字 狗狗生日 // 狗狗圖片 int[] pic =new

Java 1 Java String Date

Microsoft Word - 物件導向編程精要.doc

mvc

INTRODUCTION TO COM.DOC

任務二 : 產生 20 個有炸彈的磚塊, 放在隨機的位置編輯 Block 類別的程式碼 import greenfoot.; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) Write a description of class

nb.PDF

JavaIO.PDF


软件工程文档编制

c_cpp

提问袁小兵:

<4D F736F F D20C8EDC9E82DCFC2CEE7CCE22D3039C9CF>

Strings

epub83-1

RunPC2_.doc

使用MapReduce读取XML文件

OOP with Java 通知 Project 2 提交时间 : 3 月 14 日晚 9 点 另一名助教 : 王桢 学习使用文本编辑器 学习使用 cmd: Power shell 阅读参考资料

WebSphere Studio Application Developer IBM Portal Toolkit... 2/21 1. WebSphere Portal Portal WebSphere Application Server stopserver.bat -configfile..

多媒體應用 13 新增專案並完成版面配置 <ExMusic01> <activity_main.xml> ImageView ID imgplay ImageView ID imgstop ImageView ID imgfront TextView ID txtsong TextView ID t

全国计算机技术与软件专业技术资格(水平)考试

chp6.ppt

建立Android新專案

<4D F736F F F696E74202D20B5DA3035D5C220C3E6CFF2B6D4CFF3B8DFBCB6B3CCD0F2C9E8BCC6>

1. 访 问 最 新 发 行 公 告 信 息 jconnect for JDBC 访 问 最 新 发 行 公 告 信 息 最 新 版 本 的 发 行 公 告 可 以 从 网 上 获 得 若 要 查 找 在 本 产 品 发 布 后 增 加 的 重 要 产 品 或 文 档 信 息, 请 访

untitled

内 容 简 介 本 书 是 一 本 关 于 语 言 程 序 设 计 的 教 材, 涵 盖 了 语 言 的 基 本 语 法 和 编 程 技 术, 其 中 包 含 了 作 者 对 语 言 多 年 开 发 经 验 的 总 结, 目 的 是 让 初 学 的 读 者 感 受 到 语 言 的 魅 力, 并 掌

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

Microsoft Word - chap10.doc

, 即 使 是 在 昏 暗 的 灯 光 下, 她 仍 然 可 以 那 么 耀 眼 我 没 有 地 方 去, 你 会 带 着 我 么 杜 晗 像 是 在 嘲 笑 一 般, 嘴 角 的 一 抹 冷 笑 有 着 不 适 合 这 个 年 龄 的 冷 酷 和 无 情, 看 着 江 华 的 眼 神 毫 无 温

第7章-并行计算.ppt

060522達文西密碼_全_.PDF

ebook

Transcription:

效率的抉择 : 用 Kotlin 做 Android 开发 Bennyhuo

个人简介 霍丙乾,Bennyhuo, 就职于腾讯地图 Github: https://github.com/enbandari Kotlin 微信公众号 Kotlin 社区 :https://kotliner.cn Kotlin 博客 :https://blog.kotliner.cn

Kotlin 简介

Kotlin 的基本情况

Kotlin 的基本情况

Kotlin 的基本情况 Andrey Breslav Hadi Hariri

Kotlin 的基本情况

Kotlin 的基本情况

Kotlin 的基本情况 100% 兼容 Java

Kotlin 的基本情况

Kotlin 的基本情况

Kotlin 的基本情况 Android 官方开发语言

Kotlin 的基本情况

Kotlin 的基本情况

Kotlin 的基本情况 正式支持 JavaScript Target

Kotlin 的基本情况

Kotlin 的基本情况

Kotlin 的基本情况 Native Target 预览版 0.4

Kotlin 的基本情况

Kotlin 的基本情况

你是如何认识 Kotlin 的? 其他 15% 同学朋友 8% 缘分 13% Google IO 大会 42% JetBrains 22%

你从事何种职业? 其他 13% 服务端研发 14% 学生 17% Android 研发 56%

你或者你所在的项目如何使用 Kotlin 的? 其他 2% 不敢用 16% 全部使用 Kotlin 17% Demo 开发 44% 小范围线上 21%

你觉得 Kotlin 最吸引你的特性是什么? 没有分号 5% 属性代理 3% DSL 4% 协程 4% 数据类型 10% Lambda/ 高阶函数 25% 空安全类型 18% 跨平台一统江湖 17% 扩展方法 14%

你所在的公司人数? 10000 以上 9% 1000-10000 12% 50 人以下 41% 200-1000 19% 50-200 19%

你的年龄范围? 85 后 17% 其他 1% 80 后 8% 00 后 2% 95 后 25% 90 后 47%

Kotlin 高端大气上档次

相关资料

Android developer 地址 : https://developer.android.com/kotlin/index.html

Kotlin 官网 地址 : http://kotlinlang.org/

Kotlin 官网 ( 中文版 ) 地址 :https://www.kotlincn.net/

Kotlin 论坛 地址 :https://discuss.kotlinlang.org/

Kotlin 论坛 ( 中文版 ) 地址 :https://kotliner.cn/

Kotlin 博客 地址 :https://blog.jetbrains.com/kotlin

Kotlin 博客 ( 中文版 ) 地址 :https://blog.kotliner.cn/

Kotlin 公众号 微信公众号 :Kotlin

Kotlin 教学视频 O'Reilly Introduction to Kotlin Programming:http://hadihariri.com/2016/11/01/oreillykotlin-course/ O'Reilly Advanced Kotlin Programming:http://hadihariri.com/2016/11/01/oreilly-kotlincourse/ Github Kotlin 入门到 放弃 :https://github.com/enbandari/kotlin-tutorials 慕课网 Kotlin 入门到进阶 :http://coding.imooc.com/class/108.html

培训目标 认识 Kotlin 了解 Kotlin 的基本语法 熟悉 Kotlin 特性的一些应用场景 最后把培训的内容都忘了

下面开始讲代码

Kotlin 版本 Jvm/Js 1.0 2016.2 1.1 2017 1.2 即将面世

简洁, 就要少写废话

高效, 就要少犯错误

创建工程

创建工程

配置工程 buildscript { ext.kotlin_version = '1.1.51' repositories { google() jcenter() dependencies { classpath 'com.android.tools.build:gradle:3.0.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files

配置工程 buildscript { ext.kotlin_version = '1.1.51' repositories { google() jcenter() dependencies { classpath 'com.android.tools.build:gradle:3.0.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files

配置工程 apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android {... dependencies { implementation filetree(dir: 'libs', include: ['*.jar']) implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version...

配置工程 apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android {... dependencies { implementation filetree(dir: 'libs', include: ['*.jar']) implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version...

如何定义变量 int anint = 2;

如何定义变量 val anint: Int = 2

如何定义变量 val anint: Int = 2

如何定义变量 val anint = 2

如何定义变量 val anint = 2 anint = 3

如何定义变量 val anint = 2 anint = 3

如何定义变量 var anint = 2 anint = 3

如何定义变量 val anint = 2 final int anint = 2; var anint = 2 int anint = 2; Kotlin Java

如何定义函数 void hello(int anint){ System.out.println(anInt);

如何定义函数 fun hello(anint: Int): Unit{ println(anint)

如何定义函数 fun hello(anint: Int): Unit{ println(anint)

如何定义函数 fun hello(anint: Int) { println(anint)

如何定义函数 fun hello(anint: Int) { println(anint)

如何定义函数 fun hello(anint: Int) { println(anint)

如何定义函数 fun hello(anint: Int) { println(anint)

如何定义函数 fun hello(anint: Int) { println(anint)

如何定义函数 fun hello(anint: Int): Unit{ println(anint)

如何定义数组 int[] intarray = new int[5]; int[] anotherintarray = {1,2, 3,4,5;

如何定义数组 val intarray = IntArray(5) val anotherintarray = intarrayof(1, 2, 3, 4, 5)

如何定义数组 int[] intarray = new int[5];

如何定义数组 int[] intarray = new int[5]; for (int i = 0; i < intarray.length; i++) { intarray[i] = i;

如何定义数组 val intarray = IntArray(5){ it

如何定义数组 val intarray = IntArray(5){ it * 2

如何操作数组 intarray[1] = 2; int element3 = intarray[3] ;

如何操作数组 intarray[1] = 2 val element3 = intarray[3]

运算符 intarray[1] = 2 intarray.set(1, 2) val element3 = intarray[3] val element3 = intarray.get(3) 如果是 List Set 呢?

运算符 class 逗你玩 { operator fun set(int: Int, value: Any){ operator fun get(int: Int) = Unit

运算符 class 逗你玩 { operator fun set(int: Int, value: Any){ operator fun get(int: Int) = Unit val 逗你玩的实例 = 逗你玩 () 逗你玩的实例 [2] = 3 val x = 逗你玩的实例 [1]

WARNING 请不要用中文编程, 不然你可能找不到工作

数组的类型 基本类型的数组 ShortArray/IntArray/LongArray/FloatArray/DoubleArray/CharArray/Bool eanarray 其他类型数组 val stringarray = Array(5){ it.tostring() // Array<String> val anotherstringarray = arrayof("hello", "world") val strings = arrayofnulls<string>(5)

数组的类型 基本类型的数组 ShortArray/IntArray/LongArray/FloatArray/DoubleArray/CharArray/Bool eanarray 其他类型数组 val stringarray = Array(5){ it.tostring() // Array<String> val anotherstringarray = arrayof("hello", "world") val strings = arrayofnulls<string>(5)

数组的类型 基本类型的数组 ShortArray/IntArray/LongArray/FloatArray/DoubleArray/CharArray/Bool eanarray 其他类型数组 val stringarray = Array(5){ it.tostring() // Array<String> val anotherstringarray = arrayof("hello", "world") val strings = arrayofnulls<string>(5)

如何定义类 interface AnInterface{ class SuperClass{ public SuperClass() { class SubClass extends SuperClass implements AnInterface{ public SubClass() { super();

如何定义类 interface AnInterface class SuperClass(){ class SubClass : SuperClass(), AnInterface{

如何定义类 interface AnInterface class SuperClass{ class SubClass : SuperClass(), AnInterface{

如何定义类 interface AnInterface class SuperClass class SubClass : SuperClass(), AnInterface

如何定义类 interface AnInterface class SuperClass class SubClass : SuperClass(), AnInterface

如何定义类 interface AnInterface open class SuperClass class SubClass : SuperClass(), AnInterface

如何定义类 interface AnInterface open class SuperClass class SubClass : SuperClass(), AnInterface

如何实例化类 SubClass subclass = new SubClass();

如何实例化类 val subclass = new SubClass()

如何实例化类 val subclass = new SubClass()

如何实例化类 val subclass = SubClass()

如何实例化类 var subclass = SubClass()

构造方法 interface AnInterface open class SuperClass class SubClass : SuperClass(), AnInterface

构造方法 interface AnInterface open class SuperClass( aparam: Int ) class SubClass : SuperClass( 10 ), AnInterface

构造方法 interface AnInterface open class SuperClass(aParam: Int) { init { println(aparam) val aproperty = aparam class SubClass : SuperClass(10), AnInterface

构造方法 interface AnInterface open class SuperClass(aParam: Int) { init { println(aparam) val aproperty = aparam class SubClass ( aparamforsuper: Int ) : SuperClass( aparamforsuper ), AnInterface

构造方法 class SubClass( val apropertyinsub: String, aparamforsuper: Int ) : SuperClass( aparamforsuper ), AnInterface

构造方法 class SubClass( val apropertyinsub: String, aparamforsuper: Int ) : SuperClass( aparamforsuper ), AnInterface val subclass = SubClass("Hello", 10) subclass.

构造方法 public class Call { private String callid;

构造方法 public class Call { private String callid; public Call(String callid) { this.callid = callid;

构造方法 public class Call { private String callid; public Call(){ // 稍后再初始化 callid public Call(String callid) { this.callid = callid;

构造方法 public class Call { private final String callid; public Call(String callid) { this.callid = callid;

构造方法 class Call(val callid: String)

构造方法 class Call(val callid: String){ constructor()

构造方法 class Call(val callid: String){ constructor()

构造方法 class Call(val callid: String){ constructor(): this()

构造方法 public ViewGroup(Context context) { this(context, null); public ViewGroup(Context context, AttributeSet attrs) { this(context, attrs, 0); public ViewGroup(Context context, AttributeSet attrs, int defstyleattr) { this(context, attrs, defstyleattr, 0); public ViewGroup(Context context, AttributeSet attrs, int defstyleattr, int defstyleres) { super(context, attrs, defstyleattr, defstyleres);...

构造方法 public SomeViewGroup(Context context) { super(context); init(); public SomeViewGroup(Context context, AttributeSet attrs) { super(context, attrs); init();

构造方法 public SomeViewGroup(Context context) { super(context); init(); initdata(); public SomeViewGroup(Context context, AttributeSet attrs) { super(context, attrs); init();

构造方法 public SomeViewGroup(Context context) { super(context); init(); initdata(); public SomeViewGroup(Context context, AttributeSet attrs) { super(context, attrs); init(); initdata();

构造方法 public SomeViewGroup(Context context) { super(context); init(); initdata(); public SomeViewGroup(Context context, AttributeSet attrs) { super(context, attrs); init(); initdata();

方法重载 public interface List<E> extends Collection<E> {... public E remove(int location); public boolean remove(object object);...

方法重载 public interface List<E> extends Collection<E> {... public E remove(int location); public boolean remove(object object);... List<Integer> integers = new ArrayList<>();... integers.remove(2);

方法重载 public interface List<E> extends Collection<E> {... public E remove(int location); public boolean remove(object object);... val integers = ArrayList<Int>()... integers.removeat(2)

方法重载 public interface List<E> extends Collection<E> {... public E remove(int location); public boolean remove(object object);... val integers = ArrayList<Int>()... integers.removeat(2)

默认参数 class SomeViewGroup(context: Context, attrs: AttributeSet?, defstyleattr: Int, defstyleres: Int) : ViewGroup(context, attrs, defstyleattr, defstyleres) { init {...

默认参数 class SomeViewGroup(context: Context, attrs: AttributeSet? = null, defstyleattr: Int = 0, defstyleres: Int = 0) : ViewGroup(context, attrs, defstyleattr, defstyleres) { init {...

覆写父类成员 @Override protected void onresume() { super.onresume(); tencentmapview.onresume(); @Override protected void onpause() { super.onpause(); tencentmapview.onpause();

覆写父类成员 public class MyMapView extends MapView {... public void onresume() { dosomethingonresume(); @Override public void onpause() { super.onpause(); dosomethingonpause();...

覆写父类成员 class MyMapView(context: Context) : MapView(context) { fun onresume() { dosomethingonresume() override fun onpause() { super.onpause() dosomethingonpause()

覆写父类成员 class MyMapView(context: Context) : MapView(context) { override fun onresume() { dosomethingonresume() override fun onpause() { super.onpause() dosomethingonpause()

属性代理 public class Link { private double length = -1; private List<LatLng> points;...

属性代理 public void update(latlng latlng){... if(length == -1){ length = resolvelength();... private double resolvelength(){ return...;

属性代理 public void update(latlng latlng){... double length = getlength();... public double getlength(){ if(length == -1){ length = resolvelength(); return length; private double resolvelength(){ return...;

属性代理 private val length by lazy { resolvelength() private fun resolvelength(): Double { return...

属性代理 private val length by lazy {...

属性代理 private val length by lazy( SYNCHRONIZED ) {...

属性代理 enum class LazyThreadSafetyMode { SYNCHRONIZED, PUBLICATION, NONE,

属性代理 inline operator fun <T> Lazy<T>.getValue( thisref: Any?, property: KProperty<*> ): T = value

属性代理 private var _value: Any? = UNINITIALIZED_VALUE override val value: T get() { if (_value === UNINITIALIZED_VALUE) { _value = initializer!!() initializer = null return _value as T

属性代理 private var _value: Any? = UNINITIALIZED_VALUE override val value: T get() { if (_value === UNINITIALIZED_VALUE) { _value = initializer!!() initializer = null return _value as T private val length by lazy {...

属性代理 public interface ReadWriteProperty<in R, T> { public operator fun getvalue(thisref: R, property: KProperty<*>): T public operator fun setvalue(thisref: R, property: KProperty<*>, value: T)

属性代理 class PropertiesDelegate <T> (val path: String): ReadWriteProperty <Any, T> { val properties: Properties by lazy {... // 读属性 override operator fun getvalue(thisref: Any, property: KProperty<*>): T { val value = properties[property.name] val classoft = property.returntype.classifier as KClass<*> return if (Number::class.isSuperclassOf(classOfT)) {... // 如果是数值需要做一些转换 else { value as T override operator fun setvalue(thisref: Any, property: KProperty<*>, value: T) { properties[property.name] = value... // 存属性

属性代理 class PropertiesDelegate (val path: String) { val properties: Properties by lazy {... // 读属性 operator fun <T> getvalue(thisref: Any, property: KProperty<*>): T { val value = properties[property.name] val classoft = property.returntype.classifier as KClass<*> return if (Number::class.isSuperclassOf(classOfT)) {... // 如果是数值需要做一些转换 else { value as T operator fun <T> setvalue(thisref: Any, property: KProperty<*>, value: T) { properties[property.name] = value... // 存属性

属性代理 abstract class AbsProperties(path: String) { protected val prop = PropertiesDelegate(path)

属性代理 abstract class AbsProperties(path: String) { protected val prop = PropertiesDelegate(path) object MetaInfo: AbsProperties("/meta.properties"){ val version: String by prop val author: String by prop val name: String by prop val desc: String by prop

属性代理 object MetaInfo: AbsProperties("/meta.properties"){ val version: String by prop val author: String by prop val name: String by prop val desc: String by prop version=1.0-snapshot author=bennyhuo@kotliner.cn name=qcloudimageuploader desc= 方便地批量上传指定目录的图片到腾讯云的免费 50G 图床

属性代理 link: <https://api.github.com/user/repos?page=2>; rel="next", <https://api.github.com/user/repos?page=5>; rel="last"

属性代理 link: <https://api.github.com/user/repos?page=2>; rel="next", <https://api.github.com/user/repos?page=5>; rel="last"

属性代理 map["next"] = "https://api.github.com/user/repos?page=2" map["last"] = "https://api.github.com/user/repos?page=5"

属性代理 map["next"] = "https://api.github.com/user/repos?page=2" map["last"] = "https://api.github.com/user/repos?page=5" map["first"] = "https://api.github.com/user/repos?page=1" map["prev"] = "https://api.github.com/user/repos?page=1"

属性代理 class GitHubPaging{ val islast: Boolean =? val isfirst: Boolean =? val hasprev: Boolean =? val hasnext: Boolean =? operator fun get(key: String): String?{ return?

属性代理 class GitHubPaging{ val first: String? =? val last: String? =? val next: String? =? val prev: String? =? val islast: Boolean =? val isfirst: Boolean =? val hasprev: Boolean =? val hasnext: Boolean =?

属性代理 class GitHubPaging{ val first by map... val isfirst get() = first == null... 参考 Kotlin 公众号文章 : 用 Map 为你的属性做代理

属性代理 object Settings { var lastpage by pref(0) var daynightmode by pref(false) var enablepush by pref(false) 参考 Kotlin 公众号文章 : 用 Map 为你的属性做代理

接口代理 interface PageManager { fun showpage(clazz: KClass<out Page>) fun goback()

接口代理 class PageManagerImpl: PageManager{ override fun showpage(clazz: KClass<out Page>) {... override fun goback() {... override fun dismiss() {..

接口代理 abstract class AbstractPage(val pagemanager: PageManager) : Page, PageManager { override fun showpage(clazz: KClass<out Page>) { pagemanager.showpage(clazz) override fun goback() { pagemanager.goback() override fun dismiss() { pagemanager.dismiss()

接口代理 abstract class AbstractPage(val pagemanager: PageManager) : Page, PageManager by pagemanager{

接口代理 abstract class AbstractPage(val pagemanager: PageManager) : Page, PageManager by pagemanager

扩展成员 inline operator fun <T> Lazy<T>.getValue( thisref: Any?, property: KProperty<*> ): T = value

扩展成员 inline operator fun <T> Lazy<T>.getValue( thisref: Any?, property: KProperty<*> ): T = value

扩展成员 inline operator fun <T> Lazy<T>.getValue( thisref: Any?, property: KProperty<*> ): T = value

扩展成员 inline operator fun <T> Lazy<T>.getValue( thisref: Any?, property: KProperty<*> ): T = value

扩展成员 public class DensityUtil { /** * 根据手机的分辨率从 dp 的单位转成为 px( 像素 ) */ public static int dip2px(float dpvalue) { final float scale = ContextHolder.getInstance().getContext().getResources().getDisplayMetrics().density; return (int) (dpvalue * scale + 0.5f); /** * 根据手机的分辨率从 px( 像素 ) 的单位转成为 dp */ public static int px2dip(float pxvalue) { final float scale = ContextHolder.getInstance().getContext().getResources().getDisplayMetrics().density; return (int) (pxvalue / scale + 0.5f);

扩展成员 //returns dip(dp) dimension value in pixels fun Context.dip(value: Int): Int = (value * resources.displaymetrics.density).toint() fun Context.dip(value: Float): Int = (value * resources.displaymetrics.density).toint() //return sp dimension value in pixels fun Context.sp(value: Int): Int = (value * resources.displaymetrics.scaleddensity).toint() fun Context.sp(value: Float): Int = (value * resources.displaymetrics.scaleddensity).toint() //converts px value into dip or sp fun Context.px2dip(px: Int): Float = px.tofloat() / resources.displaymetrics.density fun Context.px2sp(px: Int): Float = px.tofloat() / resources.displaymetrics.scaleddensity

扩展成员 listview.scrollx = dip(2) paint.strokewidth = dip(2).tofloat() paint.textsize = sp(12).tofloat()

扩展成员 logger.error("*************************") logger.error("++++++++++++++++")

扩展成员 fun String.times(other: Int): String{ return (1..other).fold(StringBuilder()){ acc, i -> acc.append(this) acc.tostring()

扩展成员 logger.error("*************************") logger.error("++++++++++++++++")

扩展成员 logger.error("*".times(8) ) logger.error("+".times(8) )

扩展成员 fun String.times(other: Int): String{ return (1..other).fold(StringBuilder()){ acc, i -> acc.append(this) acc.tostring()

扩展成员 operator fun String.times(other: Int): String{ return (1..other).fold(StringBuilder()){ acc, i -> acc.append(this) acc.tostring()

扩展成员 logger.error("*".times(8) ) logger.error("+".times(8) )

扩展成员 logger.error("*" * 8 ) logger.error("+" * 8 )

运算符 a + b a - b a.plus(b) a.minus(b) a * b a / b a.times(b) a.div(b)

扩展成员 String formatteddate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); Java

扩展成员 new Date().format("yyyy-MM-dd") Groovy

扩展成员 val formatteddate = SimpleDateFormat("yyyy-MM-dd").format(Date()) Kotlin

扩展成员 fun Date.format(format: String) : String{ return SimpleDateFormat(format).format(this)

扩展成员 fun Date.format(format: String) : String = SimpleDateFormat(format).format(this)

扩展成员 fun Date.format(format: String) = SimpleDateFormat(format).format(this)

扩展成员 val formatteddate = SimpleDateFormat("yyyy-MM-dd").format(Date()) Kotlin

扩展成员 val formatteddate = Date().format("yyyy-MM-dd")

如何比较对象 String astring = "Hello Kotliner"; String anotherstring = new String("Hello Kotliner"); System.out.println(aString == anotherstring); System.out.println(aString.equals(anotherString)); System.out.println(aString == anotherstring.intern()); System.out.println(aString.equals(anotherString.intern()));

如何比较对象 String astring = "Hello Kotliner"; String anotherstring = new String("Hello Kotliner"); System.out.println(aString == anotherstring); System.out.println(aString.equals(anotherString)); System.out.println(aString == anotherstring.intern()); System.out.println(aString.equals(anotherString.intern()));

如何比较对象 val astring = "Hello Kotliner" val anotherstring = String("Hello Kotliner")

如何比较对象 val astring = "Hello Kotliner" val anotherstring = String("Hello Kotliner")

如何比较对象 val astring = "Hello Kotliner" val anotherstring = String("Hello Kotliner".toByteArray()) println(astring === anotherstring) println(astring == anotherstring) println(astring === anotherstring.intern()) println(astring == anotherstring.intern())

如何比较对象 val astring = "Hello Kotliner" val anotherstring = String("Hello Kotliner".toByteArray()) println(astring === anotherstring) println(astring == anotherstring) println(astring === anotherstring.intern()) println(astring == anotherstring.intern())

如何比较对象 val astring = "Hello Kotliner" val anotherstring = String("Hello Kotliner".toByteArray()) println(astring === anotherstring) println(astring == anotherstring) println(astring === anotherstring.intern()) println(astring == anotherstring.intern())

如何比较对象 val astring = "Hello Kotliner" val anotherstring = String("Hello Kotliner".toByteArray()) println(astring === anotherstring) println(astring == anotherstring) println(astring === anotherstring.intern()) println(astring == anotherstring.intern())

如何比较对象 val astring = "Hello Kotliner" val anotherstring = String("Hello Kotliner".toByteArray()) println(astring === anotherstring) println(astring.equals(anotherstring)) println(astring === anotherstring.intern()) println(astring.equals(anotherstring.intern()))

如何比较对象 a == b a.equals(b) a === b a == b Kotlin Java

如何比较对象 var anint =... var anotherint =... if(anint < anotherint){ println("anint < anotherint") else { println("anint > anotherint")

如何比较对象 var anint =... var anotherint =... if(anint.compareto( anotherint ) < 0){ println("anint < anotherint") else { println("anint > anotherint")

运算符 a == b a.equals(b) a < b a.compareto(b) < 0 a > b a.compareto(b) > 0 a >= b 和 a <= b 呢?

数据类 public class Link { private String id; private double length; private String name; private String attributes; public String getid() { return id; public void setid(string id) { this.id = id;... // Getters/Setters