Search code examples
javaandroidandroid-version

Code containing 3.x API class signature doesn't crush on a 2.x device. Why?


Recently I've been looking into tutorials on API backwards compatibility. Obviously ActionBar is not present in 2.* versions and I wonder how is it possible to run code like this on a 2.x device:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    ActionBar bar = getActionBar();
}

I would expect the app to crush due to being unable to find ActionBar class but it doesn't.

Any insights?


Solution

  • There is no attempt to load the class (and hence crash), since the execution never enters the if-block.