Re:Swift 2.2 Released
by lern_too_spel on Tuesday March 22, 2016 @10:51PM
(#11341770)
Passing in the class type for instantiating a new instance is not what you should do in your applications. You don't know at compile time if the class you pass in has a default constructor, so your program can fail at runtime. As others have stated, the right thing to do is pass in a factory object. C# solves this by adding even more cruft to the language in the form of a "new constraint" that tells the compiler to ensure that the type has a default constructor. https://msdn.microsoft.com/en-us/library/sd2w2ew5.aspx
[ Parent
| on HN ]
There are no comments on this comment yet.