代码之家  ›  专栏  ›  技术社区  ›  Anjani Mittal

使用kotlin error提供的参数无法调用以下函数

  •  0
  • Anjani Mittal  · 技术社区  · 6 年前

    我尝试了一些kotlin的基础知识->

    课程:

    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: 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")
    

    如果你知道我做错了什么,我会遵循这一点-> https://www.toptal.com/software/kotlin-android-language

    1 回复  |  直到 6 年前
        1
  •  4
  •   Sasi Kumar    5 年前

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

    因为kotlin默认的打印功能是这样的

    /** 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使用

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

    而不是

    print("TEST", "$day-$month-$year $hour:$minute:$second")
    
        2
  •  0
  •   ARUN PRASAD    4 年前

    在线错误

    createDate(1,7,1997)
    

    因为调用createDate()函数 不匹配 .

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