2

The Scala-Lang docs say:

Long, a 64-bit signed integer (equivalent to Java's long primitive type) is a subtype of scala.AnyVal. Instances of Long are not represented by an object in the underlying runtime system.

Java has a long (primitive) and Long (boxed).

Does Scala have aboxed version of this primitive?

1
  • 1
    Scala uses java.lang.Long as the boxed version where necessary. Same with all other primitive types. Commented Jan 31, 2014 at 5:50

1 Answer 1

5

Scala boxes and unboxes silently, so there is just one class. The compiler will try to use primitive values when it can, and uses boxed values when it can't. This happens using the Value Class mechanisms, which are classes that have specific properties that allow the compiler to take them apart when possible.

More on value classes: http://docs.scala-lang.org/overviews/core/value-classes.html

Sign up to request clarification or add additional context in comments.

1 Comment

Technically, Long is a special case, and not something that derives from value class rules. One would better not expect Long to abide by these rules.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.