64

How do I insert a code snippet in KDoc, Kotlin's default documentation tool?

In Java, I can use the following:

/** * Example usage: * * <pre> * <code>&#64;JavaAnnotation * public void foo() { * // Code * } * </code> * </pre> */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface JavaAnnotation {} 

There seems to be no equivalent in Kotlin. I tried using Markdown, but inserting 2 spaces after line end does not line-break.

1 Answer 1

118

You can use triple backticks:

/** * Example usage: * * ``` * @JavaAnnotation * public void foo() { * // Code * } * ``` */ 
Sign up to request clarification or add additional context in comments.

1 Comment

Tilde (~~~) works, too. It might be easier to type.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.