How is it possible I can cast a View into a LinearLayout?
android
Solution
`LinearLayout` is a `ViewGroup`, a `View` that contains other views. Hence you can cast a `View` to a `ViewGroup` This is what you're doing
(LinearLayout) this.findViewById(R.id.mainid);
Currently think the `View` before the cast is
View v = LinearLayout(R.id.mainid)
The actual object type is `LinearLayout`
You can cast down to `LinearLayout` because that is the actual type of the object
Problem
I'm not sure why Android allows me to do this? Or is this even valid? I have code like this: ``` LinearLayout linearLayout = (LinearLayout) this.findViewById(R.id.mainid); ``` findViewById returns a View, but I'm casting it to a LinearLayout which extends a ViewGroup. Wouldn't this be a dangerous thing to do since, I'm getting none of the the LinearLayout properties that may need to be set? Or wouldn't calling one of the methods from this cast cause issues since we have not allocated memory to it yet?