While working in the analyzer, I got this analysis error:

For some reason, the inferred type is Object. If I change this to this as Element2 then the error goes away:

However, if I rewrite the code using if/else, there is no problem without the cast:

As far as I can tell, these are functionally the same?
The class ConstructorElementImpl2 is an Element2 via this chain: ConstructorElementImpl2 extends ExecutableElementImpl2 extends FunctionTypedElementImpl2 extends TypeParameterizedElementImpl2 extends ElementImpl2 implements Element2.