Home > Mobile >  Kotlin: Multiline function name (with backticks)
Kotlin: Multiline function name (with backticks)

Time:11-10

How can I escape a function name so that it can span multiple lines? For example

@Test
fun `This is a really long description of what should happen to this function when the IDs do not match up.`() {
  // test
}

What I would want is something like

@Test
fun `This is a really long description of what should happen to this \
     function when the IDs do not match up.`() { // test }

Is this possible?

CodePudding user response:

It is not possible, function names convention allows spaces in test methods but not multiple lines : https://kotlinlang.org/docs/coding-conventions.html#names-for-test-methods

In tests (and only in tests), you can use method names with spaces enclosed in backticks.

A method with multiple lines in its name would not be callable even through reflection. (see https://stackoverflow.com/a/45750788/7346454)

  • Related