简体   繁体   中英

what does def * (def asterisk) mean?

an example in some code I'm looking at

class X {
    def k1 = column[Int]("k1")
    def k2 = column[Int]("k2")
    def * = (k1, k2)
}

Is it just a normal function name or is there something special about it?

It's the name of an abstract method in Slick 's Table , used to tell Slick how it should convert those columns into a Scala object, and the Scala object back into the database columns. The complete code in your question would be

class X(tag: Tag) extends Table[(Int, Int)] {
    def k1 = column[Int]("k1")
    def k2 = column[Int]("k2")
    override def * : ProvenShape[(Int, Int)] = (k1, k2) // you may prefer to omit 'override' and return type for readability
}

So, if you extend Table , you have to override this method.

You can find more complex usages in the documentation .

It is just a normal function name. Scala allows pretty much any sequence of characters to be a function name, though some need to be quoted using backticks.

def `def` = "def"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM