#1227 List.map return type

vkuzkokov Wed 22 Sep 2010

This topic is closely related #1222 about That and generics in general. For example I have a list of pods as Str[] and want to make them Depend[]

ci.depends     = depends.map |s->Depend| { Depend(s) }

That's an actual line of code from $FAN_HOME/src/build/fan/BuildPod.fan. It appears to differ semantically from

ci.depends     = depends.map { Depends(s) }

The latter shall result in runtime error because it will return Obj?[] when Depend[] is expected.

This one is mostly caused by "middle of the road" approach when some but not all types are resolved at compile time. AFAIK that's the second way to create List which has element type defined at runtime (the first being calling List.make).

In short, I was surprised to find that out.

Login or Signup to reply.