oop - Scala's hierarchy mapped to Java's -
as "programming in scala: comprehensive step-by-step guide" states, in scala there not basic types values, objects: integers int instances , doubles double instances. assume these classes map java's integer, double ... classes and, therefore, mapped object subclasses.
in book, next type hierarchy (classes types) presented:
few pages after graph presented, can read:
what somehow troubles me is: if scala´s double maps java's double specification of java.lang.object , anyref alias java.lang.object too, should't anyval subclass of anyref?
edit
few pages after read primitive types not mapped java's primitive types wrapper classes unless "boxed" versions required; still confused since seems me not scala's objects java.lang.object sublcasses instances. is: there classes in scala not translated in jvm object subclasses.
java not have types extend java.lang.object (aka scala.anyref), primitive types, e.g. int, double, boolean, ... in scala find them under scala.any. scala.int corresponds java int. not java.lang.integer; not until boxing occurs, mechanism on jvm able pass primitives generic methods. both java , scala auto-boxing, build reference around primitive type when reference needed.
the difference in scala is, doesn't treat scala.int different string, doesn't matter whether type corresponds jvm primitive or not. can phone call methods on scala.int if regular object. in byte-code still have primitive types.
this why scala called true or more pure object-oriented language java.
scala oop
No comments:
Post a Comment