How get generic parameter in scala -



How get generic parameter in scala -

i able perform next code:

abstract class a[t <: anyref]{ def whichclass: class[_] = classof[t] } case class x() object b extends a[x] object main{ def main(args: array[string]){ b.whichclass //should homecoming classof[x] } }

clearly, doesn't work in form, since classof[t] can assignged class, not type. got error:

error: class type required t found def whichclass: class[_] = classof[t]

any thought how solve problem in way?

use classmanifest.

abstract class a[t <: anyref : classmanifest] { def whichclass = classmanifest[t].erasure } case class x() object b extends a[x] object main{ def main(args: array[string]): unit = { println(b.whichclass) // prints 'class x' } }

generics scala

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -