fun createRequest(
url: String,
method: String = "GET",
timeoutMs: Int = 30_000,
followRedirects: Boolean = true,
userAgent: String = "myapp/1.0",
) {
println("$method $url (timeout=${timeoutMs}ms)")
}
fun main() {
// Positional — easy when there's only one or two args
createRequest("https://example.com")
createRequest("https://example.com", "POST")
// Named — skip middle defaults, document call site
createRequest(
url = "https://api.example.com",
timeoutMs = 5_000,
followRedirects = false,
)
// Mix positional + named: positionals first, then named
createRequest("https://example.com", timeoutMs = 1_000)
// Java callers don't get named args — use @JvmOverloads if needed:
// @JvmOverloads fun createRequest(url: String, method: String = "GET", ...)
}
Create a free account and build your private vault. Share publicly whenever you want.