如何做到高级Kotlin强化实战?(三)
创始人
2024-12-28 07:04:36
0

高级Kotlin强化实战(二)

          • 2.13 constructor 构造器
          • 2.14 Get Set 构造器
          • 2.15 操作符
          • 2.16 换行


2.13 constructor 构造器
//Java public class Utils { private Utils() {   } public static int getScore(int value) { return 2 * value;   } } 
//Kotlin class Utils private constructor() { companion object { fun getScore(value: Int): Int { return 2 * value     }   } } // 或者 object Utils { fun getScore(value: Int): Int { return 2 * value   } } 

2.14 Get Set 构造器
//Java public class Developer { private String name; private int age; public Developer(String name, int age) { this.name = name; this.age = 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; } } 
//kotlin data class Developer(val name: String, val age: Int) 

2.15 操作符
//Java final int andResult = a & b; final int orResult = a | b; final int xorResult = a ^ b; final int rightShift = a >> 2; final int leftShift = a << 2; final int unsignedRightShift = a >>> 2;  
//kotlin val andResult = a and b val orResult = a or b val xorResult = a xor b val rightShift = a shr 2 val leftShift = a shl 2 val unsignedRightShift = a ushr 2 

2.16 换行
//Java String text = "First Line\n" + "Second Line\n" + "Third Line"; 
//kotlin val text = """ |First Line |Second Line |Third Line """.trimMargin() 

相关内容

热门资讯

今日头条(WePoKe抽水)总... 今日头条(WePoKe抽水)总是有挂(透视)都是存在有挂(有挂解惑)-哔哩哔哩是一款可以让一直输的玩...
科普攻略(AAPoKer开发)... 科普攻略(AAPoKer开发)外挂透明挂辅助插件(AAPOKeR)透明挂购买(一贯真的有挂)-哔哩哔...
重大推荐!丽水茶苑双扣有外挂(... 您好:丽水茶苑双扣有外挂这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的...
黑科技辅助(WPK可测试)外挂... 黑科技辅助(WPK可测试)外挂透明挂辅助挂(透视)好像真的有挂(2023已更新)(哔哩哔哩);WPK...
一分钟揭秘(Wepoke稳定)... 一分钟揭秘(Wepoke稳定)都是真的有挂(透视)原本是有挂(有挂工具)-哔哩哔哩;亲,有的,ai轻...
推荐一款(WePoKe黑科技)... 推荐一款(WePoKe黑科技)外挂透明挂辅助神器(aapokEr)德州辅助器ai(原先是有挂)-哔哩...
一分钟揭秘!福建大玩家有后台(... 一分钟揭秘!福建大玩家有后台(辅助挂)原生是有挂(有挂方略)-哔哩哔哩是一款可以让一直输的玩家,快速...
黑科技辅助(德州数据)外挂透明... 黑科技辅助(德州数据)外挂透明挂辅助下载(透视)原生真的是有挂(2025已更新)(哔哩哔哩);1.德...
科技分享(云扑克苹果版)好像有... 科技分享(云扑克苹果版)好像有挂(透视)从前有挂(新版有挂)-哔哩哔哩;是一款可以让一直输的玩家,快...
发现玩家(WPK脚本)外挂透明... 发现玩家(WPK脚本)外挂透明挂辅助器(约局吧)透明挂软件(一向真的有挂)-哔哩哔哩;超受欢迎的约局...