- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Use of java.lang.Long in scala code
Sat, 2009-11-21, 01:05
Hi,
This might be silly ... Do you how to set a java.lang.Long variable to a var.
I need to use java.lang.Long because of datanucleus-enhance bytecode instrumentation fails otherwise.
My code looks like:
package org.kkarad.liftplayground.model
import javax.jdo.annotations._
@PersistenceCapable{val identityType = IdentityType.APPLICATION}
class Candidate {
@PrimaryKey
@Persistent{val valueStrategy = IdGeneratorStrategy.IDENTITY}
var id: java.lang.Long = -1
@Persistent
var content: String = ""
}
The compiler error is:
error: type mismatch;
found : Int(-1)
required: java.lang.Long
var id: java.lang.Long = -1
^
Thank you in advance,
Kostas
This might be silly ... Do you how to set a java.lang.Long variable to a var.
I need to use java.lang.Long because of datanucleus-enhance bytecode instrumentation fails otherwise.
My code looks like:
package org.kkarad.liftplayground.model
import javax.jdo.annotations._
@PersistenceCapable{val identityType = IdentityType.APPLICATION}
class Candidate {
@PrimaryKey
@Persistent{val valueStrategy = IdGeneratorStrategy.IDENTITY}
var id: java.lang.Long = -1
@Persistent
var content: String = ""
}
The compiler error is:
error: type mismatch;
found : Int(-1)
required: java.lang.Long
var id: java.lang.Long = -1
^
Thank you in advance,
Kostas
Sat, 2009-11-21, 01:37
#2
Re: Use of java.lang.Long in scala code
I think this version is a tiny bit more efficient, don't take my word
for it though. You may also prefer the look of the thing:
val lng = java.lang.Long.valueOf(-1L)
I've not thrown this one at my compiler either... :(
On Saturday, November 21, 2009, David Pollak
wrote:
>
> scala> var lng: java.lang.Long = -1L
> lng: java.lang.Long = -1
>
> scala>
>
>
>
>
> On Fri, Nov 20, 2009 at 4:05 PM, Konstantinos Karadamoglou > wrote:
> Hi,
>
> This might be silly ... Do you how to set a java.lang.Long variable to a var.
>
> I need to use java.lang.Long because of datanucleus-enhance bytecode instrumentation fails otherwise.
>
> My code looks like:
>
> package org.kkarad.liftplayground.model
>
> import javax.jdo.annotations._
>
> @PersistenceCapable{val identityType = IdentityType.APPLICATION}
> class Candidate {
>
> @PrimaryKey
> @Persistent{val valueStrategy = IdGeneratorStrategy.IDENTITY}
> var id: java.lang.Long = -1
>
> @Persistent
> var content: String = ""
> }
>
> The compiler error is:
> error: type mismatch;
> found : Int(-1)
> required: java.lang.Long
> var id: java.lang.Long = -1
> ^
>
> Thank you in advance,
>
> Kostas
>
>
>
> --
> Lift, the simply functional web framework http://liftweb.net
> Beginning Scala http://www.apress.com/book/view/1430219890
> Follow me: http://twitter.com/dpp
> Surf the harmonics
>
Sat, 2009-11-21, 01:57
#3
Re: Use of java.lang.Long in scala code
Thank you
On Sat, Nov 21, 2009 at 12:30 AM, Kevin Wright <kev.lee.wright@googlemail.com> wrote:
On Sat, Nov 21, 2009 at 12:30 AM, Kevin Wright <kev.lee.wright@googlemail.com> wrote:
I think this version is a tiny bit more efficient, don't take my word
for it though. You may also prefer the look of the thing:
val lng = java.lang.Long.valueOf(-1L)
I've not thrown this one at my compiler either... :(
On Saturday, November 21, 2009, David Pollak
<feeder.of.the.bears@gmail.com> wrote:
>
> scala> var lng: java.lang.Long = -1L
> lng: java.lang.Long = -1
>
> scala>
>
>
>
>
> On Fri, Nov 20, 2009 at 4:05 PM, Konstantinos Karadamoglou <kkarad@googlemail.com <javascript:_e({}, 'cvml', 'kkarad@googlemail.com');>> wrote:
> Hi,
>
> This might be silly ... Do you how to set a java.lang.Long variable to a var.
>
> I need to use java.lang.Long because of datanucleus-enhance bytecode instrumentation fails otherwise.
>
> My code looks like:
>
> package org.kkarad.liftplayground.model
>
> import javax.jdo.annotations._
>
> @PersistenceCapable{val identityType = IdentityType.APPLICATION}
> class Candidate {
>
> @PrimaryKey
> @Persistent{val valueStrategy = IdGeneratorStrategy.IDENTITY}
> var id: java.lang.Long = -1
>
> @Persistent
> var content: String = ""
> }
>
> The compiler error is:
> error: type mismatch;
> found : Int(-1)
> required: java.lang.Long
> var id: java.lang.Long = -1
> ^
>
> Thank you in advance,
>
> Kostas
>
>
>
> --
> Lift, the simply functional web framework http://liftweb.net
> Beginning Scala http://www.apress.com/book/view/1430219890
> Follow me: http://twitter.com/dpp
> Surf the harmonics
>
Sat, 2009-11-21, 17:07
#4
Re: Use of java.lang.Long in scala code
Another question is how can I convert scala.Long to java.lang.Long and java.lang.Long to scala.Long?
Thank you in advance.
On Sat, Nov 21, 2009 at 12:54 AM, Konstantinos Karadamoglou <kkarad@googlemail.com> wrote:
Thank you in advance.
On Sat, Nov 21, 2009 at 12:54 AM, Konstantinos Karadamoglou <kkarad@googlemail.com> wrote:
Thank you
On Sat, Nov 21, 2009 at 12:30 AM, Kevin Wright <kev.lee.wright@googlemail.com> wrote:
I think this version is a tiny bit more efficient, don't take my word
for it though. You may also prefer the look of the thing:
val lng = java.lang.Long.valueOf(-1L)
I've not thrown this one at my compiler either... :(
On Saturday, November 21, 2009, David Pollak
<feeder.of.the.bears@gmail.com> wrote:
>
> scala> var lng: java.lang.Long = -1L
> lng: java.lang.Long = -1
>
> scala>
>
>
>
>
> On Fri, Nov 20, 2009 at 4:05 PM, Konstantinos Karadamoglou <kkarad@googlemail.com <javascript:_e({}, 'cvml', 'kkarad@googlemail.com');>> wrote:
> Hi,
>
> This might be silly ... Do you how to set a java.lang.Long variable to a var.
>
> I need to use java.lang.Long because of datanucleus-enhance bytecode instrumentation fails otherwise.
>
> My code looks like:
>
> package org.kkarad.liftplayground.model
>
> import javax.jdo.annotations._
>
> @PersistenceCapable{val identityType = IdentityType.APPLICATION}
> class Candidate {
>
> @PrimaryKey
> @Persistent{val valueStrategy = IdGeneratorStrategy.IDENTITY}
> var id: java.lang.Long = -1
>
> @Persistent
> var content: String = ""
> }
>
> The compiler error is:
> error: type mismatch;
> found : Int(-1)
> required: java.lang.Long
> var id: java.lang.Long = -1
> ^
>
> Thank you in advance,
>
> Kostas
>
>
>
> --
> Lift, the simply functional web framework http://liftweb.net
> Beginning Scala http://www.apress.com/book/view/1430219890
> Follow me: http://twitter.com/dpp
> Surf the harmonics
>
Sat, 2009-11-21, 21:47
#5
Re: Use of java.lang.Long in scala code
java.lang.Long.valueOf(scala.Long)
someJavaLong.longValue
2009/11/21 Konstantinos Karadamoglou :
> Another question is how can I convert scala.Long to java.lang.Long and
> java.lang.Long to scala.Long?
>
> Thank you in advance.
>
> On Sat, Nov 21, 2009 at 12:54 AM, Konstantinos Karadamoglou
> wrote:
>>
>> Thank you
>>
>> On Sat, Nov 21, 2009 at 12:30 AM, Kevin Wright
>> wrote:
>>>
>>> I think this version is a tiny bit more efficient, don't take my word
>>> for it though. You may also prefer the look of the thing:
>>>
>>> val lng = java.lang.Long.valueOf(-1L)
>>>
>>> I've not thrown this one at my compiler either... :(
>>>
>>>
>>> On Saturday, November 21, 2009, David Pollak
>>> wrote:
>>> >
>>> > scala> var lng: java.lang.Long = -1L
>>> > lng: java.lang.Long = -1
>>> >
>>> > scala>
>>> >
>>> >
>>> >
>>> >
>>> > On Fri, Nov 20, 2009 at 4:05 PM, Konstantinos Karadamoglou
>>> > >> > 'kkarad@googlemail.com');>> wrote:
>>> > Hi,
>>> >
>>> > This might be silly ... Do you how to set a java.lang.Long variable to
>>> > a var.
>>> >
>>> > I need to use java.lang.Long because of datanucleus-enhance bytecode
>>> > instrumentation fails otherwise.
>>> >
>>> > My code looks like:
>>> >
>>> > package org.kkarad.liftplayground.model
>>> >
>>> > import javax.jdo.annotations._
>>> >
>>> > @PersistenceCapable{val identityType = IdentityType.APPLICATION}
>>> > class Candidate {
>>> >
>>> > @PrimaryKey
>>> > @Persistent{val valueStrategy = IdGeneratorStrategy.IDENTITY}
>>> > var id: java.lang.Long = -1
>>> >
>>> > @Persistent
>>> > var content: String = ""
>>> > }
>>> >
>>> > The compiler error is:
>>> > error: type mismatch;
>>> > found : Int(-1)
>>> > required: java.lang.Long
>>> > var id: java.lang.Long = -1
>>> > ^
>>> >
>>> > Thank you in advance,
>>> >
>>> > Kostas
>>> >
>>> >
>>> >
>>> > --
>>> > Lift, the simply functional web framework http://liftweb.net
>>> > Beginning Scala http://www.apress.com/book/view/1430219890
>>> > Follow me: http://twitter.com/dpp
>>> > Surf the harmonics
>>> >
>>
>
>
Sat, 2009-11-21, 22:47
#6
Re: Use of java.lang.Long in scala code
Thanks Ricky,
What about java.lang.Long to scala.Long ?
I tried a simple assignment but it fails.
scala> val x: Long = java.lang.Long.valueOf(1)
<console>:4: error: type mismatch;
found : java.lang.Long
required: Long
val x: Long = java.lang.Long.valueOf(1)
I am assuming these conversions are documented somewhere. Does anyone know where to find the relevant documentation?
Kostas
On Sat, Nov 21, 2009 at 8:36 PM, Ricky Clarkson <ricky.clarkson@gmail.com> wrote:
What about java.lang.Long to scala.Long ?
I tried a simple assignment but it fails.
scala> val x: Long = java.lang.Long.valueOf(1)
<console>:4: error: type mismatch;
found : java.lang.Long
required: Long
val x: Long = java.lang.Long.valueOf(1)
I am assuming these conversions are documented somewhere. Does anyone know where to find the relevant documentation?
Kostas
On Sat, Nov 21, 2009 at 8:36 PM, Ricky Clarkson <ricky.clarkson@gmail.com> wrote:
java.lang.Long.valueOf(scala.Long)
someJavaLong.longValue
2009/11/21 Konstantinos Karadamoglou <kkarad@googlemail.com>:
> Another question is how can I convert scala.Long to java.lang.Long and
> java.lang.Long to scala.Long?
>
> Thank you in advance.
>
> On Sat, Nov 21, 2009 at 12:54 AM, Konstantinos Karadamoglou
> <kkarad@googlemail.com> wrote:
>>
>> Thank you
>>
>> On Sat, Nov 21, 2009 at 12:30 AM, Kevin Wright
>> <kev.lee.wright@googlemail.com> wrote:
>>>
>>> I think this version is a tiny bit more efficient, don't take my word
>>> for it though. You may also prefer the look of the thing:
>>>
>>> val lng = java.lang.Long.valueOf(-1L)
>>>
>>> I've not thrown this one at my compiler either... :(
>>>
>>>
>>> On Saturday, November 21, 2009, David Pollak
>>> <feeder.of.the.bears@gmail.com> wrote:
>>> >
>>> > scala> var lng: java.lang.Long = -1L
>>> > lng: java.lang.Long = -1
>>> >
>>> > scala>
>>> >
>>> >
>>> >
>>> >
>>> > On Fri, Nov 20, 2009 at 4:05 PM, Konstantinos Karadamoglou
>>> > <kkarad@googlemail.com <javascript:_e({}, 'cvml',
>>> > 'kkarad@googlemail.com');>> wrote:
>>> > Hi,
>>> >
>>> > This might be silly ... Do you how to set a java.lang.Long variable to
>>> > a var.
>>> >
>>> > I need to use java.lang.Long because of datanucleus-enhance bytecode
>>> > instrumentation fails otherwise.
>>> >
>>> > My code looks like:
>>> >
>>> > package org.kkarad.liftplayground.model
>>> >
>>> > import javax.jdo.annotations._
>>> >
>>> > @PersistenceCapable{val identityType = IdentityType.APPLICATION}
>>> > class Candidate {
>>> >
>>> > @PrimaryKey
>>> > @Persistent{val valueStrategy = IdGeneratorStrategy.IDENTITY}
>>> > var id: java.lang.Long = -1
>>> >
>>> > @Persistent
>>> > var content: String = ""
>>> > }
>>> >
>>> > The compiler error is:
>>> > error: type mismatch;
>>> > found : Int(-1)
>>> > required: java.lang.Long
>>> > var id: java.lang.Long = -1
>>> > ^
>>> >
>>> > Thank you in advance,
>>> >
>>> > Kostas
>>> >
>>> >
>>> >
>>> > --
>>> > Lift, the simply functional web framework http://liftweb.net
>>> > Beginning Scala http://www.apress.com/book/view/1430219890
>>> > Follow me: http://twitter.com/dpp
>>> > Surf the harmonics
>>> >
>>
>
>
--
Ricky Clarkson
Java and Scala Programmer, AD Holdings
+44 1565 770804
Skype: ricky_clarkson
Google Talk: ricky.clarkson@gmail.com
Google Wave: ricky.clarkson@googlewave.com
Sat, 2009-11-21, 23:17
#7
Re: Use of java.lang.Long in scala code
Instead of looking for exaples in specific cases, it's easier to remember that scala.Long is directly equivalent to the long primitive in Java.When calling a Java function that needs a long, you supply a scala.Long, when a java function returns a long, you'll see a scala.Long
In the compiled bytecode, there's absolutely no difference between long an scala.Long, it's all a trick of the compiler...
So in answer to your question, to convert a java.lang.Long to a scala.Long, just call longValue on it.
On Sat, Nov 21, 2009 at 9:44 PM, Konstantinos Karadamoglou <kkarad@googlemail.com> wrote:
In the compiled bytecode, there's absolutely no difference between long an scala.Long, it's all a trick of the compiler...
So in answer to your question, to convert a java.lang.Long to a scala.Long, just call longValue on it.
On Sat, Nov 21, 2009 at 9:44 PM, Konstantinos Karadamoglou <kkarad@googlemail.com> wrote:
Thanks Ricky,
What about java.lang.Long to scala.Long ?
I tried a simple assignment but it fails.
scala> val x: Long = java.lang.Long.valueOf(1)
<console>:4: error: type mismatch;
found : java.lang.Long
required: Long
val x: Long = java.lang.Long.valueOf(1)
I am assuming these conversions are documented somewhere. Does anyone know where to find the relevant documentation?
Kostas
On Sat, Nov 21, 2009 at 8:36 PM, Ricky Clarkson <ricky.clarkson@gmail.com> wrote:java.lang.Long.valueOf(scala.Long)
someJavaLong.longValue
2009/11/21 Konstantinos Karadamoglou <kkarad@googlemail.com>:
> Another question is how can I convert scala.Long to java.lang.Long and
> java.lang.Long to scala.Long?
>
> Thank you in advance.
>
> On Sat, Nov 21, 2009 at 12:54 AM, Konstantinos Karadamoglou
> <kkarad@googlemail.com> wrote:
>>
>> Thank you
>>
>> On Sat, Nov 21, 2009 at 12:30 AM, Kevin Wright
>> <kev.lee.wright@googlemail.com> wrote:
>>>
>>> I think this version is a tiny bit more efficient, don't take my word
>>> for it though. You may also prefer the look of the thing:
>>>
>>> val lng = java.lang.Long.valueOf(-1L)
>>>
>>> I've not thrown this one at my compiler either... :(
>>>
>>>
>>> On Saturday, November 21, 2009, David Pollak
>>> <feeder.of.the.bears@gmail.com> wrote:
>>> >
>>> > scala> var lng: java.lang.Long = -1L
>>> > lng: java.lang.Long = -1
>>> >
>>> > scala>
>>> >
>>> >
>>> >
>>> >
>>> > On Fri, Nov 20, 2009 at 4:05 PM, Konstantinos Karadamoglou
>>> > <kkarad@googlemail.com <javascript:_e({}, 'cvml',
>>> > 'kkarad@googlemail.com');>> wrote:
>>> > Hi,
>>> >
>>> > This might be silly ... Do you how to set a java.lang.Long variable to
>>> > a var.
>>> >
>>> > I need to use java.lang.Long because of datanucleus-enhance bytecode
>>> > instrumentation fails otherwise.
>>> >
>>> > My code looks like:
>>> >
>>> > package org.kkarad.liftplayground.model
>>> >
>>> > import javax.jdo.annotations._
>>> >
>>> > @PersistenceCapable{val identityType = IdentityType.APPLICATION}
>>> > class Candidate {
>>> >
>>> > @PrimaryKey
>>> > @Persistent{val valueStrategy = IdGeneratorStrategy.IDENTITY}
>>> > var id: java.lang.Long = -1
>>> >
>>> > @Persistent
>>> > var content: String = ""
>>> > }
>>> >
>>> > The compiler error is:
>>> > error: type mismatch;
>>> > found : Int(-1)
>>> > required: java.lang.Long
>>> > var id: java.lang.Long = -1
>>> > ^
>>> >
>>> > Thank you in advance,
>>> >
>>> > Kostas
>>> >
>>> >
>>> >
>>> > --
>>> > Lift, the simply functional web framework http://liftweb.net
>>> > Beginning Scala http://www.apress.com/book/view/1430219890
>>> > Follow me: http://twitter.com/dpp
>>> > Surf the harmonics
>>> >
>>
>
>
--
Ricky Clarkson
Java and Scala Programmer, AD Holdings
+44 1565 770804
Skype: ricky_clarkson
Google Talk: ricky.clarkson@gmail.com
Google Wave: ricky.clarkson@googlewave.com
Sat, 2009-11-21, 23:27
#8
Re: Use of java.lang.Long in scala code
Thanks Kevin
On Sat, Nov 21, 2009 at 10:00 PM, Kevin Wright <kev.lee.wright@googlemail.com> wrote:
On Sat, Nov 21, 2009 at 10:00 PM, Kevin Wright <kev.lee.wright@googlemail.com> wrote:
Instead of looking for exaples in specific cases, it's easier to remember that scala.Long is directly equivalent to the long primitive in Java.When calling a Java function that needs a long, you supply a scala.Long, when a java function returns a long, you'll see a scala.Long
In the compiled bytecode, there's absolutely no difference between long an scala.Long, it's all a trick of the compiler...
So in answer to your question, to convert a java.lang.Long to a scala.Long, just call longValue on it.
On Sat, Nov 21, 2009 at 9:44 PM, Konstantinos Karadamoglou <kkarad@googlemail.com> wrote:Thanks Ricky,
What about java.lang.Long to scala.Long ?
I tried a simple assignment but it fails.
scala> val x: Long = java.lang.Long.valueOf(1)
<console>:4: error: type mismatch;
found : java.lang.Long
required: Long
val x: Long = java.lang.Long.valueOf(1)
I am assuming these conversions are documented somewhere. Does anyone know where to find the relevant documentation?
Kostas
On Sat, Nov 21, 2009 at 8:36 PM, Ricky Clarkson <ricky.clarkson@gmail.com> wrote:java.lang.Long.valueOf(scala.Long)
someJavaLong.longValue
2009/11/21 Konstantinos Karadamoglou <kkarad@googlemail.com>:
> Another question is how can I convert scala.Long to java.lang.Long and
> java.lang.Long to scala.Long?
>
> Thank you in advance.
>
> On Sat, Nov 21, 2009 at 12:54 AM, Konstantinos Karadamoglou
> <kkarad@googlemail.com> wrote:
>>
>> Thank you
>>
>> On Sat, Nov 21, 2009 at 12:30 AM, Kevin Wright
>> <kev.lee.wright@googlemail.com> wrote:
>>>
>>> I think this version is a tiny bit more efficient, don't take my word
>>> for it though. You may also prefer the look of the thing:
>>>
>>> val lng = java.lang.Long.valueOf(-1L)
>>>
>>> I've not thrown this one at my compiler either... :(
>>>
>>>
>>> On Saturday, November 21, 2009, David Pollak
>>> <feeder.of.the.bears@gmail.com> wrote:
>>> >
>>> > scala> var lng: java.lang.Long = -1L
>>> > lng: java.lang.Long = -1
>>> >
>>> > scala>
>>> >
>>> >
>>> >
>>> >
>>> > On Fri, Nov 20, 2009 at 4:05 PM, Konstantinos Karadamoglou
>>> > <kkarad@googlemail.com <javascript:_e({}, 'cvml',
>>> > 'kkarad@googlemail.com');>> wrote:
>>> > Hi,
>>> >
>>> > This might be silly ... Do you how to set a java.lang.Long variable to
>>> > a var.
>>> >
>>> > I need to use java.lang.Long because of datanucleus-enhance bytecode
>>> > instrumentation fails otherwise.
>>> >
>>> > My code looks like:
>>> >
>>> > package org.kkarad.liftplayground.model
>>> >
>>> > import javax.jdo.annotations._
>>> >
>>> > @PersistenceCapable{val identityType = IdentityType.APPLICATION}
>>> > class Candidate {
>>> >
>>> > @PrimaryKey
>>> > @Persistent{val valueStrategy = IdGeneratorStrategy.IDENTITY}
>>> > var id: java.lang.Long = -1
>>> >
>>> > @Persistent
>>> > var content: String = ""
>>> > }
>>> >
>>> > The compiler error is:
>>> > error: type mismatch;
>>> > found : Int(-1)
>>> > required: java.lang.Long
>>> > var id: java.lang.Long = -1
>>> > ^
>>> >
>>> > Thank you in advance,
>>> >
>>> > Kostas
>>> >
>>> >
>>> >
>>> > --
>>> > Lift, the simply functional web framework http://liftweb.net
>>> > Beginning Scala http://www.apress.com/book/view/1430219890
>>> > Follow me: http://twitter.com/dpp
>>> > Surf the harmonics
>>> >
>>
>
>
--
Ricky Clarkson
Java and Scala Programmer, AD Holdings
+44 1565 770804
Skype: ricky_clarkson
Google Talk: ricky.clarkson@gmail.com
Google Wave: ricky.clarkson@googlewave.com
scala> var lng: java.lang.Long = -1L
lng: java.lang.Long = -1
scala>
On Fri, Nov 20, 2009 at 4:05 PM, Konstantinos Karadamoglou <kkarad@googlemail.com> wrote:
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics