There is another possible generic type constraint, called default constructor or parameterless constructor. If you need to invoke the default constructor to create new object of the generic type (for example for filling a list) you can use this constraint. In theory (and according to the documentation), the compiler should let you use it only for those types with a default constructor. In practice, if a default constructor doesn't exists, the compiler will let it go and call the default constructor of TObject.
A generic class with a constructor constraint can be written as follows76 (this one is extracted by the IntfConstraint example): type
TConstrClass <T: class, constructor> = class private val: T; publ ic constructor Create; function Get: T;
Was this article helpful?
What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.