ccpplinux The compiler knows only that container.layout
is of type ILayout
. You could pass a different layout to container.layout
later, such as HorizontalLayout
or VerticalLayout
. Then, it wouldn't be FlowRowsLayout
anymore.
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();
containerLayout.setPadding(10.0);
container.layout = containerLayout;
In this style, no casting is needed.