草庐IT

switch-statement - 高效开关需要自认证吗?

显然,when表达式的编译方式取决于一个表示常量的方式:objectSwitchOverConstants{valfoo=1valbar=2valbaz=3funone(x:Int)=when(x){foo->"foo"bar->"bar"baz->"baz"else->"else"}funtwo(x:Int)=when(x){SwitchOverConstants.foo->"foo"SwitchOverConstants.bar->"bar"SwitchOverConstants.baz->"baz"else->"else"}}这是one的字节码:0:iload_11:istore

switch-statement - 高效开关需要自认证吗?

显然,when表达式的编译方式取决于一个表示常量的方式:objectSwitchOverConstants{valfoo=1valbar=2valbaz=3funone(x:Int)=when(x){foo->"foo"bar->"bar"baz->"baz"else->"else"}funtwo(x:Int)=when(x){SwitchOverConstants.foo->"foo"SwitchOverConstants.bar->"bar"SwitchOverConstants.baz->"baz"else->"else"}}这是one的字节码:0:iload_11:istore