ccpplinux The compiler knows only that
container.layout is of type
ILayout. You could pass a different layout to
container.layout later, such as
VerticalLayout. Then, it wouldn't be
Admittedly, in your code above, it's very unlikely that the layout would somehow change between the line with
new FlowRowsLayout() and the next line with
setPadding(). However, in a more complex situation, where there are additional lines in between those two, the compiler would have a very difficult time determining which layout is in use. It would need to actually run your code to know for sure, which isn't really something a compiler is supposed to do.
I usually try to set properties on the layout before I pass it to the container, like this:
var containerLayout = new FlowRowsLayout();
container.layout = containerLayout;
In this style, no casting is needed.