Scala Quiz: Unary Precedence


Scala Quiz: Unary Precedence

Without tesing with a repl, can you correctly guess all the ???.

val a = 1 implicit class RichInt(val x: Int) { def s: Int = { println(s"got x = $x") 2 } } /* Expression | Print | Returns -----------|------------|--------- -(1.s) | ??? | ??? -(a.s) | ??? | ??? -a.s | ??? | ??? -1.s | ??? | ??? */ implicit class RichInt2(val x: Int) { def s: String = { println(s"got x = $x") s"returning x = $x" } } /* Expression | Compiles | Print | Returns -----------|----------|------------|--------- -(1.s) | ??? | ??? | ??? -(a.s) | ??? | ??? | ??? -a.s | ??? | ??? | ??? -1.s | ??? | ??? | ??? */ 

Submitted February 21, 2018 at 11:39PM by MasGui
via reddit http://ift.tt/2CbT8v4

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s