传送门
个人认为Kotlin语言非常优雅,与Java相比,增加了很多特性和语法糖,在使用过程中也有了一定的思考,并做了一些简单的记录。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| public class People {
private String name; private int age;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getAge() { return age; }
public void setAge(int age) { this.age = age; }
@Override public String toString() { return "People{" + "name='" + name + '\'' + ", age=" + age + '}'; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; People people = (People) o; return age == people.age && Objects.equals(name, people.name); } }
|
1 2 3 4 5
| fun View.getViewLocationArr(): IntArray { val viewLoc = intArrayOf(0, 0) getLocationOnScreen(viewLoc) return viewLoc }
|
1 2 3 4 5 6 7 8
| @NotNull public static final int[] getViewLocationArr(@NotNull View $receiver) { Intrinsics.checkParameterIsNotNull($receiver, "$receiver"); int[] viewLoc = { 0, 0 }; $receiver.getLocationOnScreen(viewLoc); return viewLoc; }
|
1 2 3 4 5 6 7 8 9
| animator?.addListener(object : AnimatorListenerAdapter() { override fun onAnimationStart(animation: Animator?) {
}
override fun onAnimationEnd(animation: Animator?) {
} })
|
官方文档(PS:吐槽一下,Kotlin的中文文档翻译到有点生涩,有些地方不是很理解),后续本人也会发表一些关于Kotlin的文章,更多从知其所以然的角度(例如反编译代码)去认识它,学习它。