I am new to scala and am trying to write a function literal that checks if a given integer is odd or not. my first attempt:
val isOdd = (x:Int) => (x & 1) == 1
it works fine, and since the x parameter appears only once in this function literal, I am tempted to use the "_" notation to simplify it, for example:
val isOdd = ((_:Int) & 1 ) == 1
however, this time the compiler complains:
warning: comparing a fresh object using `== 'will always yield false
val isOdd = ((_: Int) & 1) == 1
What does this warning mean? why does the compiler recognize ((_ :Int) & 1)as a new object, and not a beaten operation, which leads to a value? is there any way to write this function literal using the notation "_"?