If we don't have the println()
function, is there any alternative or a way to write your print function?
CodePudding user response:
If you right-click on println in IntelliJ, you can Go to...
-> Implementation(s)
and see how Kotlin does it "under the hood". It's a bit verbose but not that complicated. Ultimately it's using a BufferedWriter
to write to the Standard Output stream.
You can replicate this yourself with something like:
import java.io.BufferedWriter
import java.io.OutputStreamWriter
fun main() {
val writer = BufferedWriter(OutputStreamWriter(System.`out`))
writer.write("No println here")
writer.newline()
writer.flush()
}