I have several methods that return java.lang.Integer, which is then implicitly converted to Int using implicit Scala Predef transformations, here's how it is written:
implicit def Integer2int(x: java.lang.Integer): Int = x.intValue
This conversion does not satisfy me, I would like something like:
implicit def Integer2int(x: java.lang.Integer): Int = Option(x).getOrElse(new Integer(0)).intValue
since Integer can sometimes be null , in which case the implicit Predef conversion also returns null, and I would like it to be 0. Instead
I wrote my own conversion, but I continue to get errors saying that this declaration is ambiguous, given that it is already declared in Predef.
My question is, is there a way to override implicit Predef conversions?
Peter source share