Home

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

android devices

android devices Emulator If you need to refer to your host computer’s localhost, such as when you want the emulator client to contact a server running on the host, use the alias 10.0.2.2 to refer to the host computer’s loopback interface. From the emulator’s perspective, localhost (127.0.0.1) refers to its own loopback interface. More details...

Read more

kotlin function

kotlin function 使用fun声明函数 可以有默认值, 默认值如果在左边, 传参需要加参数名使用命名参数; 默认值都在右边, 传参可以不加参数名; 重写时总是 使用基础函数的默认值, 重写时需要省略默认值. 支持命名参数, 不能使用命名参数调用Java代码 unit表示无返回, 可以省略 单表达式函数, 当返回一个单表达式时, 可以省略大括号和返回值, fun double(x: Int): Int = x * 2 vararg 可变数量参数, 最后封装成Array, 如果该参数不是最后一个, 就需要使用命名参数传递 支持spread operator (prefix the array with *): val a = arrayOf(...

Read more

kotlin builder

kotlin builder kotlin 使用命名良好的函数和 function literals with receiver, 可以实现type-safe builder Type-safe builders allow creating Kotlin-based domain-specific languages (DSLs) Generating markup with Kotlin code, such as HTML or XML Configuring routes for a web server: Ktor fun html(init: HTML.() -> Unit): HTML { val html = ...

Read more