Saif: In your example below, the error was due to there is no automatic conversion from Int to BigDecimal.
Cheers > On Aug 19, 2015, at 6:40 AM, <saif.a.ell...@wellsfargo.com> > <saif.a.ell...@wellsfargo.com> wrote: > > Hi, thank you all for the asssistance. > > It is odd, it works when creating a new java.mathBigDecimal object, but not > if I work directly with > > scala> 5 match { case x: java.math.BigDecimal => 2 } > <console>:23: error: scrutinee is incompatible with pattern type; > found : java.math.BigDecimal > required: Int > 5 match { case x: java.math.BigDecimal => 2 } > > I will try and see how it works for my Seq[Any] and see. Thanks for the work > arounds. > Saif > > From: Sujit Pal [mailto:sujitatgt...@gmail.com] > Sent: Tuesday, August 18, 2015 6:25 PM > To: Ellafi, Saif A. > Cc: wrbri...@gmail.com; user > Subject: Re: Scala: How to match a java object???? > > Hi Saif, > > Would this work? > import scala.collection.JavaConversions._ > > new java.math.BigDecimal(5) match { case x: java.math.BigDecimal => > x.doubleValue } > > It gives me on the scala console. > > res9: Double = 5.0 > > Assuming you had a stream of BigDecimals, you could just call map on it. > > myBigDecimals.map(_.doubleValue) > > to get your Seq of Doubles. You will need the JavaConversions._ import to > allow Java Doubles to be treated by Scala as Scala Doubles. > > -sujit > > > On Tue, Aug 18, 2015 at 12:59 PM, <saif.a.ell...@wellsfargo.com> wrote: > Hi, thank you for further assistance > > you can reproduce this by simply running > > 5 match { case java.math.BigDecimal => 2 } > > In my personal case, I am applying a map acton to a Seq[Any], so the elements > inside are of type any, to which I need to apply a proper > .asInstanceOf[WhoYouShouldBe]. > > Saif > > From: William Briggs [mailto:wrbri...@gmail.com] > Sent: Tuesday, August 18, 2015 4:46 PM > To: Ellafi, Saif A.; user@spark.apache.org > Subject: Re: Scala: How to match a java object???? > > Could you share your pattern matching expression that is failing? > > > On Tue, Aug 18, 2015, 3:38 PM <saif.a.ell...@wellsfargo.com> wrote: > Hi all, > > I am trying to run a spark job, in which I receive java.math.BigDecimal > objects, instead of the scala equivalents, and I am trying to convert them > into Doubles. > If I try to match-case this object class, I get: “error: object > java.math.BigDecimal is not a value” > > How could I get around matching java objects? I would like to avoid a > multiple try-catch on ClassCastExceptions for all my checks. > > Thank you, > Saif > >