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

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

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -