scala - When are classes extending AnyVal not unboxed? -


in https://stackoverflow.com/a/40486805/4533188 told classes extending anyval cannot unboxed compiler (so there underlaying primitives in jvm bytecode) in cases. rules when unboxing not work?

i understand if class extending anyval put collection, unboxing not work. given example generics, understand whole picture.

the documentation pretty clear on these occasions:

allocation summary

a value class instantiated when:

  • a value class treated type.
  • a value class assigned array.
  • doing runtime type tests, such pattern matching.

example of value class treated type:

trait distance extends case class meter(val value: double) extends anyval distance  def add(a: distance, b: distance): distance = ??? add(meter(3.4), meter(4.3)) 

example of value class assigned array:

val arrayofmeter: array[meter] = ??? 

example of pattern matching:

val p: meter = new meter(1.0) p match {   // ... } 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -