0

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?

midnight
  • 3,420
  • 3
  • 36
  • 58

1 Answers1

0

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

Kayaman
  • 72,141
  • 5
  • 83
  • 121
  • but it also has import. – midnight Oct 31 '14 at 12:13
  • Import has nothing to do with classloading. You could remove the import and refer to the class with its FQN. You can import anything at all (that resolves during compile time), without them ever being loaded or used at runtime. – Kayaman Oct 31 '14 at 12:14
  • You might want to look into how classloading works. When they're loaded and which classloader loads them. – Kayaman Oct 31 '14 at 12:17