Home > Enterprise >  Kotlin: How to break line after equal sign for long expressions or declarations
Kotlin: How to break line after equal sign for long expressions or declarations

Time:11-11

In Python, I can do something like

long_declaration_and_long_variable_name = \
    foo_bar.this_is_a_really_long_function_name_and_its_only_getting_longer["baz"]

Is it possible to do something like this in Kotlin?

I am fully aware that in Kotlin you can break lines for for chaining, such as

val xyz = foo_bar.this_is_shorter
    .so_I_can_break(this_up)
    .into_individual_lines(like_so)

However, in my case the function name is very long and I would simply like to have it on the next line

CodePudding user response:

I'm not sure if I get you correctly but in Kotlin you can do the same as in Python (tbh even simpler because you don't need to use \ sign)

val long_declaration_and_long_variable_name: SomeLongTypeName = 
    foo_bar.this_is_a_really_long_function_name_and_its_only_getting_longer("some long argument string")
  • Related