4 ms·
Many thanks!! So is it something like Class<List<String>> thisistypeconstructor(Class<String> strClass) And if I generify the types above, maybe something lik
by SNosTrAnDbLe 5y ago
Many thanks!! So is it something like
Class<List<String>> thisistypeconstructor(Class<String> strClass)
And if I generify the types above, maybe something like
<OutputType> thisistypeconstructor(<InputType>)
- lmm 5y agoNot quite - the type constructor is the thing that does the same thing with the types themselves, not with Class (which is sort-of-but-not-really a way to represent types as values). In Java or C# there's no way to actually represent a type constructor (e.g. you can't have a class that takes a type parameter F that could be List or Set, and then you use that type to form F<String> within the class itself and it will be List<String> or Set<String> depending on whether you do new MyClass<List> or new MyClass<Set>), but other languages are more powerful in what they let you do with types. Look up "higher-kinded types" for the general concept.
- gpderetta 5y agoFor example in C++: template<template<class> class F, class T> using apply = F<T>; static_assert(is_same_v<apply<list, string>, list<string> >);