In this recipe, we are going to explore how to add custom names to the import declarations. We are going to import the java.lang.StringBuilder class, add a custom name to it and make use of it in the sample code to demonstrate it in action.
Adding custom names for imports
How to do it...
- Import the StringBuilder class with a custom alias:
import java.lang.StringBuilder as builder
- Use the custom StringBuilder name in the sample code:
import java.lang.StringBuilder as builder
fun main(vararg args: String) {
val text = builder()
.append("Code is like humor. ")
.append("When you have to explain it, ")
.append("it’s bad.")
.toString()
...