2
votes

I was trying some basics of kotlin ->

program :

fun createDate(day: Int, month: Int, year: Int, hour: Int = 0, minute: Int = 0, second: Int = 0) {
print("TEST", "$day-$month-$year $hour:$minute:$second")
}
createDate(1,7,1997)

error :

error: none of the following functions can be called with the arguments supplied: 
@InlineOnly public inline fun print(message: Any?): Unit defined in kotlin.io
@InlineOnly public inline fun print(message: Boolean): Unit defined in kotlin.io
@InlineOnly public inline fun print(message: Byte): Unit defined in kotlin.io
@InlineOnly public inline fun print(message: Char): Unit defined in kotlin.io
@InlineOnly public inline fun print(message: CharArray): Unit defined in kotlin.io
@InlineOnly public inline fun print(message: Double): Unit defined in kotlin.io
@InlineOnly public inline fun print(message: Float): Unit defined in kotlin.io
@InlineOnly public inline fun print(message: Int): Unit defined in kotlin.io
@InlineOnly public inline fun print(message: Long): Unit defined in kotlin.io
@InlineOnly public inline fun print(message: Short): Unit defined in kotlin.io
print("TEST", "$day-$month-$year $hour:$minute:$second")

any idea what I am doing wrong, I was following this -> https://www.toptal.com/software/kotlin-android-language

2
print only accepts a single argument, you're passing it two.jonrsharpe
The message is relatively clear... there exist only methods that have 1 parameter, but you pass 2 (first. "TEST", second: "$day-...$second"). You may wanted to use something like: "TEST $day-...$second" instead. Note that I do not know which print-function the author of that article used... probably it's a self-built one...Roland
Oh dear... that article is already more than 2 years old and uses Kotlin version 1.0.1... you may want to use a tutorial that was written more recently or if you like the style just take it with a grain of salt...Roland

2 Answers

4
votes

It should be like this,because kotlin default print funtion have only one parameters

fun createDate(day: Int, month: Int, year: Int, hour: Int = 0, minute: Int = 0, second: Int = 0) {
    print("$day-$month-$year $hour:$minute:$second")
}

Because kotlin default print function like this

/** Prints the given message and newline to the standard output stream. */
public expect fun println(message: Any?)

 /** Prints the given message to the standard output stream. */
public expect fun print(message: Any?)

so you cant send double parameters in print function.so use

print("$day-$month-$year $hour:$minute:$second")

instead of

print("TEST", "$day-$month-$year $hour:$minute:$second")
0
votes

Error on line

createDate(1,7,1997)

because you call the createDate() function but arguments is mismatched.

Let us overwrite this function:

createDate(1,7,1997,5,24,15)