I am reasonable new to scala and working with scala and Java together.
I am trying to pass a scala Int into a method that accepts an Integer(java.long.Integer). Since they are of different types the compiler gives an error.
/* name- Option[String], id- Option[Integer] , mask- Option[String]*/
new findingFrame(name,id, mask)
case class findingFrame(name: String,
id: Option[java.lang.Integer],
mask : Option[String])
I tried using .instanceOf [java.lang.Integer], but this doesn't work either..
I am not sure how to solve this.. Can somebody help me please? Thank you.
There is another method of the Integer class called “parseInt()” that is also used to convert Integer to int. In this method, a string is accepted as an argument and gives an int value as an output.
We can convert int to String in java using String. valueOf() and Integer. toString() methods.
All you need to do is pass the int value to the constructor of Integer(). You can pass this new object now.
scala> val n = 20
n: Int = 20
scala> new Integer(n)
res0: Integer = 20
scala> res0.getClass
res1: Class[_ <: Integer] = class java.lang.Integer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With