AI代码解释 for(int i=1;i<=10;i++){}for(int i=1;i<10;i++){}for(int i=10;i>=0;i--){}for(int i=1;i<=10;i+=2){}for(int i=10;i>=0;i-=2){}for(String item:collection){}for(Map.Entry<String,String>entry:map.entrySet()){} Kotlin 代码语言:javascript 代码运行次数:...
varstorageConfig:RabbitStorageConfig=RabbitStorageConfig(),varmonitorConfig:RabbitMonitorConfig=RabbitMonitorConfig(),varreportConfig:RabbitReportConfig=RabbitReportConfig()){varage:Int=10set(value){println("setter $value")field=value}val createTimeShow:()->Stringget(...
fun main(args: Array<String>) { when (val value = getValue()) {//when表达式条件直接是一个表达式,并用value保存了返回值, 实际上相当于把外部那一行缩进来写 is Int -> "This is Int Type, value is $value".apply(::println) is String -> "This is String Type, value is $value".apply(...
enum class Direction { NORTH, SOUTH, WEST, EAST // 每个枚举常量都是一个对象, 用逗号分隔 }相比于字符串常量,使用枚举能够实现类型安全。枚举类有两个内置的属性:public final val name: String public final val ordinal: Int分别表示的是枚举对象的值跟下标位置。例如上面的Direction枚举类,它的枚举对象的...
values()returns the enum constants in the form of an array over which we can iterate to retrieve each enum constant.values()以数组的形式返回枚举常量,我们可以在该数组上进行迭代以检索每个枚举常量。 valueOf()is used to fetch an enum constant using a String as the argument.valueOf()用于使用Str...
Enumsin Kotlin make handling constants type-safe, less error-prone, and self-documented. In this tutorial, we’ll explore how to convert a string into an enum object. 2. Introduction to the Problem As usual, let’s understand the problem through an example. Let’s say we have the enum ...
其中有些 Action 是关联的,有些则没有关联、不是同一层级。但是 enum class 默认扩展自 Enum 类,无法再嵌套 enum。 Enum class cannot inherit from classes 这将导致层级混乱、阅读性不佳,甚至有的时候功能相近的时候还得特意取个不同的名称。 enum class Action {Tick,// GameActionStart, Exit, Restart,//...
fun foo2(str : String?): String? { //do-something return null } 使用let、run、apply、also等内联函数,尤其是在“链式调用”写法的时候,一定要当心它们的返回值。 扩展:什么是内联函数? 所谓内联函数就是指函数在被调用的地方直接展开,编译器在调用时不用像一般函数那样,参数压栈,返回时参数出栈以及资...
*/privateString createBy;/** * Update人;Update人 */privateString updateBy;/** * 是否Delete;是否Delete */@LogicDelete(strategy = LogicDeleteStrategyEnum.BOOLEAN)privateBoolean deleted; }@Data@Table("t_topic")@EntityProxy//or @EntityFileProxy@ToStringpublicclassTopicimplementsProxyEntityAvailable<Top...
enum class ThreadModel {// 默认模式,无论post是在子线程或主线程,接收方法的线程为post时的线程。// 不进行线程切换POSTING,// 主线程模式,无论post是在子线程或主线程,接收方法的线程都切换为主线程。MAIN,// 主线程模式,无论post是在子线程或主线程,接收方法的线程都切换为主线程。// 这个在EventBus源码...