kotlin -- Type inference failed: Cannot infer type parameter

kotlin – Type inference failed: Cannot infer type parameter


import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.SchemaUtils.create
import org.jetbrains.exposed.sql.SchemaUtils.drop


object CollegeEntranceExam: Table() {
    val id = integer("Id").primaryKey().uniqueIndex()
    val adress = varchar("Adress", length = 10).nullable()
    val score = decimal("Score",3,1).default(0)// error: Type inference failed: Cannot infer type parameter...
}

fun main(args: Array) {
    Database.connect("jdbc:mysql://localhost/ktdb",
            driver = "com.mysql.jdbc.Driver",
            user = "k", password = "")

    transaction {
        logger.addLogger(StdOutSqlLogger)
        create(CollegeEntranceExam)

        drop(CollegeEntranceExam)
    }
}

kotlin -- Type inference failed: Cannot infer type parameter_第1张图片
  在使用kotlin的exposed框架时定义decimal的默认值时发生错误,解决方案是把0替换成BigDecimal.valueOf(0.0):

object CollegeEntranceExam: Table() {
    val id = integer("Id").primaryKey().uniqueIndex()
    val adress = varchar("Adress", length = 10).nullable()
    val score = decimal("Score",3,1).default(BigDecimal.valueOf(0.0))
}

你可能感兴趣的:(kotlin,kotlin-exposed,exposed框架,kotlin编程,kotlin指南,kotlin,Kotlin)