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

Popular posts from this blog

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

ruby on rails - Authlogic - how to make a registration and don't log in the new account? -