Kenji
Kenji
CC#
Created by Kenji on 5/31/2023 in #help
✅ Recursive type definition
This is valid (basically CRTP):
class Base<T> { }
class Derived<T> : Base<Derived<T>> { }
class Base<T> { }
class Derived<T> : Base<Derived<T>> { }
This is not, because if you instantiate anywhere a new Derived<SomeType>(), the program panics with TypeLoaderException because of "recursive generic definition"
class Base<T> { }
class Derived<T> : Base<Derived<Derived<T>>> { }
class Base<T> { }
class Derived<T> : Base<Derived<Derived<T>>> { }
I cannot understand the different between these two generic definitions. If I specify SomeType, I would imagine that the generics should expand as expected and resolve the types correctly, as kind-0 types, e.g.: Derived<int> : Base<Derived<Derived<int>>> The only thing I could find is the official explanation on the CLI Standard here on page 129 https://www.ecma-international.org/publications-and-standards/standards/ecma-335/, but I do not quite get it. 🙂 Any ideas?
34 replies