scala - objects of same class have different methods signature -
look @ next snippet:
class c val c1 = new c { def m1 = "c1 has m1" } val c2 = new c { def m2 = "c2 has m2" } c1.m1 c2.m2 //c2.m1 //c1.m2
run in repl, know mean.
my limited java knowledge tells me in java, objects of same class have same methods signagure, , far oo concerned, there no much difference between java , scala under hood. (correct me, if i'm wrong), i'm surprised see snippet sound scala code.
so why?
you're extending c
traits, c1
, c2
anonymous classes :
scala> c1.getclass res0: java.lang.class[_ <: c] = class $anon$1 scala> c2.getclass res1: java.lang.class[_ <: c] = class $anon$2
looking @ java code, you'll see (o
beingness surrounding object compile) :
public final class o$$anon$1 extends o$c { public java.lang.string m1(); public o$$anon$1(); } public final class o$$anon$2 extends o$c { public java.lang.string m2(); public o$$anon$2(); }
scala
No comments:
Post a Comment