class - In Scala EVERYTHING is an Object - are Classes Objects? -
i ran scala.reflect.runtime api , tried generate classdefinitins stringevaluation. here aproach made in scala repl:
scala> import scala.reflect.runtime._ import scala.reflect.runtime._ scala> val cm = universe.runtimemirror(getclass.getclassloader) cm: reflect.runtime.universe.mirror = javamirror scala.tools.n[....] scala> import scala.tools.reflect.toolbox import scala.tools.reflect.toolbox scala> val tb = cm.mktoolbox() tb: scala.tools.reflect.toolbox[reflect.runtime.universe.type] = scala.to[...] scala> tb.eval(tb.parse("class a; scala.reflect.classtag[a].runtimeclass")) res0: = class __wrapper$1$c6a9fb3f39c2499a9ff6e29384816f58.__wrapper$[...]
since answer repl not:
defined class a
but
res0: = class __wrapper$1$c6a9fb3f39c2499a9ff6e29384816f58.__wrapper$[...]
i started wonder if created class or kind of initialized abstract instance? once read in scala object. if res0 in repl holds class, mean, classes objects in scala? cant find more input im confused. if classes not objects in scala res0 hold @ moment? in advance help.
no, classes not objects in strict sense, neither methods. scala runs on jvm , scala classes , methods compile down concepts of jvm.
what meant "everything object" every value object, i.e. native values, instances, functions.
however, there objects give access meta information of classes , methods. if this
res0.getclass
you see, res0 instance of (java) class class. have gotten object jvm reflection api.
the repl not give "defined class a" because have defined in other context.
by way, instead of scala.reflect.classtag[a].runtimeclass
have written classof[a]
.
Comments
Post a Comment