Checking Android Versions and Inserting Static Finite Constants

As I understand it, and constants static finalare built in at compile time when using Java.

Looking at Using Version-Aware Component - add switching logic and usage Build.VERSION.SDK_INTand it Build.VERSION_CODESbothers me as if both constant values ​​are built in at compile time, this approach would be useless. What am I missing here?

Thank:)

EDIT: Does the fact that they are in a static method in an abstract class change this compile-time insertion?

+5
source share
1 answer

What is inlined are constants that can be determined at compile time, for example:

private final int CONST = 1;

( , , ), :

public static final String SDK = getString("ro.build.version.sdk");

getString:

private static String getString(String property) {
    return SystemProperties.get(property, UNKNOWN);
}

, .

+3

All Articles