First: you cannot access it because it is closed.
Why is it closed?
As you said, direct access to members is faster. On the other hand, you call a method that is not very fast, because it will look for some kind of view hierarchy. Therefore, using the method instead of direct access will result in a small overhead as a percentage of the total time it takes to complete this task.
In any case, I believe that the reason for this is encapsulation.
You call what you don't have (this is the Android SDK). Thus, you should not make any assumptions about what is happening “on the other hand”. Just use this method and expect it to return the view you want (or null if it does not exist).
Perhaps the next version of android will use a different method to search for the view, and not to call getWindow() . If you use this method, they (Google / Android) can simply mark the method as deprecated and “forward” your call to the latest implementation. If you called getWindow() directly, you might be looking for something that is no longer hosted there.
Pedro loureiro
source share