scala - Is there a utility for polymorphic object creation somewhere in the standard library -
i write utility in projects:
def instance[t](implicit m: manifest[t]) = m.erasure.newinstance.asinstanceof[t]
it looks in standard library, have not been able find it. did miss it? if not powers add :)
edit
if runtime exceptions when t lacks no-arg constructor unacceptable 1 can define
def maybeinstance[t:manifest] = try some(instance[t]) catch {case _ => none}
possibly making underlying instance
function private. however, many standard functions throw runtime exceptions, including division & many networking operation.
Comments
Post a Comment