templates1.htm
 
  • Through templates the programming languages, provide parametric polymorphisms,  facilitating type (data-type) safe (meaning by passing runtime errors;
  • If not specialized for any data type, default is void type, meaning would accept any data-type.
  • Allow generic algorithms and data structures, encapsulated in a class.
  • Template works like a run-time code optimizer, reduces run time over head and memory foot prints.
  • C# 2.0
    List<Person> foo = new List<Person>();
    • C# does not allow non-type template parameters, such as template C<int i> {}.
    • C# generics do not provide the same amount of flexibility as C++ templates.
    • Further readings ref: 2
  • Java
    • simple
      List<String> list12 = new ArrayList<>();
      List<Person1> foo1 = new ArrayList<Person1>();
      List<Person1> foo2 = new ArrayList<>();
    • Observable:
      ObservableList<String> oString1 = FXCollections.<String>observableArrayList(ext1.list1);
  • C++
    exmple1 ,
 
 
 
 

References:

  1. http://stackoverflow.com/questions/31693/what-are-the-differences-between-generics-in-c-sharp-and-java-and-templates-i?noredirect=1&lq=1
  2. https://msdn.microsoft.com/en-us/library/c6cyy67b.aspx