I wanted to perform bitwise and operation in an if condition, and based on the matching condition return a particular int.
def test(x: Int): Int= { var y = 0 if(x & 3 == 3){ y = 3 } else if( //another condition) { y = 8 } y }
However, I keep on getting this error: overloaded method value & with alternatives:
cannot be applied to (Boolean) if(x & 3 == 3)
if(x & 3 == 3)
I started exploring this Scala Int Compare Method.
Is this approach correct?
def test2(x: Int): Int= { var y = 0 if((x & 3).compare(3) == 0){ y = 3 } y }
1.4m articles
1.4m replys
5 comments
56.9k users