+1 I’m also struggling with this; especially how to deal with generics if there is no defaults in kotlin (is there?). If there is generic property, does it need to be forced into a nullable, to be able to initialize it? And everything needs dummy =null? looking for something like default(T) in c#
“Default” values as you suggest are often poor design. The philosophy is that the object is always in a valid state except while executing the constructor (and finalizer). Basically all values are provided by the constructor based on its parameters. The primary constructor syntax with variables is a concrete push towards this concept. The only way to initialize generics is when the generic value is assigned through the constructor as it disappears at runtime and the class cannot interrogate its generic parameters.
The question is “What does key== null even mean? What are you trying to access and what should be the result”.
There are only two options (as far as I can tell)
null is a valid key, therefor it should be handled like any other
null is an invalid key, therefor the code should raise an exception
So let’s say you have a different use case that needs default values. The only way I know is to pass in the default value. You could do that when creating your MapLoader object or if you have control over the function API add it as an additional parameter.