Skip to content

Instantly share code, notes, and snippets.

@xeno-by
Created April 20, 2012 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeno-by/2428930 to your computer and use it in GitHub Desktop.
Save xeno-by/2428930 to your computer and use it in GitHub Desktop.
Fun with units
Welcome to Scala version 2.10.0-20120418-145922-016bc3db52 (Java HotSpot(TM) 64-Bit Server VM, Java
1.6.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> Array[Unit]((), ())
typechecking macro expansion materializeClassTag[Unit](`package`.this.mirror) at source-<console>,li
ne-8,offset=101
ClassTag.Unit
Select(Ident(newTermName("ClassTag")), newTermName("Unit"))
res0: Array[Unit] = Array((), ())
scala> res0.getClass
res1: Class[_ <: Array[Unit]] = class [Lscala.runtime.BoxedUnit;
scala> res0(0).getClass
res2: Class[Unit] = void
scala> new Array[Unit](2)
res3: Array[Unit] = Array((), ())
scala> res3.getClass
res4: Class[_ <: Array[Unit]] = class [Lscala.runtime.BoxedUnit;
scala> res3(0).getClass
scala.MatchError: null
at scala.runtime.ScalaRunTime$.anyValClass(ScalaRunTime.scala:54)
at .<init>(<console>:8)
at .<clinit>(<console>)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:775)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$16.apply(IMain.scala:1039)
at scala.tools.nsc.interpreter.Line.scala$tools$nsc$interpreter$Line$$runAndSetState(Line.scala:41)
at scala.tools.nsc.interpreter.Line$$anonfun$2.apply$mcV$sp(Line.scala:47)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:22)
at java.lang.Thread.run(Thread.java:662)
scala> res3(0)
scala> val x = res3(0)
x: Unit = ()
scala> x.getClass
res7: Class[Unit] = void
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment