I created the following function:
public fun storeImage(image: BufferedImage, toPath: String,
onCompletion: (contentURL: URL) -> Unit)
{
val file = File(this.storageDirectory, toPath)
log.debug("storing image: ${file.absolutePath}")
val extension = toPath.extensionOrNull()
if (!file.exists())
{
file.parentFile.mkdirs()
file.createNewFile()
}
ImageIO.write(image, extension!!, FileOutputStream(file.absolutePath))
onCompletion(URL(contentBaseUrl, toPath))
}
I can see that I can call it like this:
contentManager.storeImage(image, "1234/Foobar.jpg", onCompletion = {
println("$it")
})
Or I can use trailing closure syntax:
contentManager.storeImage(image, "1234/Foobar.jpg") {
println("$it")
}
But how do I call the store image method and call the onCompletion function using named parameters?
Edit/Example:
I would like to call the storeImage method using a syntax similar to:
contentManager.storeImage(image, "1234/Foobar.jpg",
onCompletion = (bar: URL) : Unit -> {
//do something with bar
}
I could not find the correct syntax in the docs for the above kind of thing.
contentURLparam? Because with theonCompletion = ...thing you're already using named parameters.onCompletion(in thestoreImagefun) can have named params "for documentation". In the definition ofonCompletionyou'd still need to use the closure syntax:onCompletion = { contentURL -> /* do stuff */ }. On the call site, you're not allowed to name the param:onCompletion(URL(...)).