Is Unit a singleton?

As Unit type has only one value, does it mean Unit is a singleton?

Yes, it its. Keep in mind that scala.Unit object is not extending scala.Unit class. The singleton is not actually defined anywhere - exists only during compilation phase. It’s converted to scala.runtime.BoxedUnit when it’s value is needed.

1 Like