How can I write "/*" in a kotlin comment?

Viewed 481

How can I write /* in a kotlin comment in a span code?

For example:

/**
 * Defines the route `/route/*`
 */
fun defineRoute() { 
    /* ... */ 
}

Right now, according to Kotlin, /route/* is the beginning of a nested comment (so the whole file is commented). I'm using /route/{*} for now but it's not a decent solution.

3 Answers

You could use HTML escaping, so in your example:

/**
 * Defines the route /route/*
 */
fun defineRoute() { 
    /* ... */ 
}

should achieve the desired result since

/ escapes as a "/"

you can add a backslash before the /* like this:

/* say something \/*
*/
fun defineRoute() { 
/* ... */ 
}

You can also just close the nested comment:

/**
 * Defines the route `/route/*`
 */*/
fun defineRoute() { 
    /* ... */ 
}

This has the benefit of breaking once they fix the Kotlin parser, to be reminded to remove these.

Related