典型代码整理

新Feature、重构等判断其他模块是否支持,使用类反射

// android.os/MessageQueue.java
private static void initIsProcessAllowedToUseConcurrent() {
        if (sIsProcessAllowedToUseConcurrent != null) {
            return;
        }
 
        if (Flags.forceConcurrentMessageQueue()) {
            // b/379472827: Robolectric tests use reflection to access MessageQueue.mMessages.
            // This is a hack to allow Robolectric tests to use the legacy implementation.
            try {
                Class.forName("org.robolectric.Robolectric");
            } catch (ClassNotFoundException e) {
                // This is not a Robolectric test.
                sIsProcessAllowedToUseConcurrent = true;
                return;
            }
            // This is a Robolectric test.
            // Continue to the following checks.
        }
 
    .....
    }