Home

kotlin destructuring declarations

kotlin destructuring declarations val (name, age) = person 被翻译成: val name = person.component1() val age = person.component2() for ((a, b) in collection) { ... } Reference

Read more

kotlin this

kotlin this To denote the current receiver, you use this expressions: * In a member of a class, this refers to the current object of that class. * In an extension function or a function literal with receiver this denotes the receiver parameter that is passed on the left-hand side of a dot. If this has no qualifiers, it refers to the innermo...

Read more

kotlin null safety

kotlin null safety kotlin中产生NPE的原因: * 显示调用throw NullPointerException() * 使用!!调用null引用 * 使用未正确初始化的引用 - a leaking this - 超类构造函数中使用在子类初始化的open member * Java集成 - 访问null引用 - java把null添加到kotlin MutableList - 由外部java 代码 避免使用null: 1. 显示使用if检查null, 变量需要是不可变的(保证使用时变量值不是null), 编译器会跟踪检查信息. ...

Read more

kotlin equality

kotlin equality In Kotlin there are two types of equality: * Structural equality (== - a check for equals()) * Referential equality (=== - two references point to the same object) Structural equality a == b -> a?.equals(b) ?: (b === null) Floating-point numbers equality IEEE 754 -0.0 != 0.0 Reference

Read more

kotlin async

kotlin async * Threading * Callbacks * Futures, promises, and others * Reactive Extensions * Coroutines threading 线程需要上下文切换, 消耗大 线程根据操作系统定义最大数量 有些语言不支持线程 线程编程容易出错, 并且不容易调试 callbacks titled christmas tree. 嵌套函数不容易理解 嵌套函数使错误处理很复杂. javascript 中很常见, 目前已改用promises和reactive extensions Futures, promises, and others 不同的编...

Read more

kotlin annotations

kotlin annotations // 声明注解 annotation class Fancy 使用meta-annotations可以指定注解的属性: @Target可以指定哪种元素可以使用这个注解 @Retention指定1: 是否存储在编译后的类中; 2: 指定是否运行时反射可见(默认两者都有) @Repeatable允许同一个元素使用注解多次 @MustBeDecumented指定注解属于公共API, 在文档中显示 Constructors 注解可以有构造函数 annotation class Special(val why: String) @Special("example") class Foo {} 构造函数允许的参数...

Read more

aria2

aria2 安装Apache2 sudo apt install apache2 sudo systemctl status apache2 安装AriaNg 把包解压到/var/www/html中, 通过ip+80端口访问 配置aria2 下载aria2源码 sudo apt install autoconf autopoint aptitude autoreconf -i ./configure ./configure ARIA2_STATIC=yes sudo make install sudo aria2c –conf-path=/etc/aria2/aria2.con...

Read more

android img

android img How to Create Bitmap From View in Android? RelativeLayout relativeLayout = (RelativeLayout) LayoutInflater.from(mContext.get()).inflate(R.layout.widget_week_cal_item, null); int width = getItemWidth(); int height = getPx(20); relativeLayout.layout(0, 0, width, height); int measuredWidth = View.MeasureSpec.makeMeasureSpec(width, V...

Read more