freechipsproject / chisel-bootcamp

Generator Bootcamp Material: Learn Chisel the Right Way
Apache License 2.0
957 stars 275 forks source link

I have a question about scala grammar in 3.6 #172

Closed linuxlonelyeagle closed 1 year ago

linuxlonelyeagle commented 1 year ago

Sorry,I haven't been learning scala for long,i meet some question in 3.6.

def time[T](block: => T): T = {
    val t0 = System.nanoTime()
    val result = block
    val t1 = System.nanoTime()
    val timeMillis = (t1 - t0) / 1000000.0
    println(s"Block took $timeMillis milliseconds!")
    result
}

There's one thing I don't understand about the (block: => T),Why (block: => T) can appear here? I know this function has no parameters.But I still don't understand,sorry.If anyone can help me, I would be grateful!Thanks!