Example: Math.FMA is not available in Java 8 but we want to use it
regularly.

1) Sub-Project FMA8
public class FMA {
    public static float fma(float a, float b, float c) {
        return a * b + c;
    }

    public static double fma(double a, double b, double c) {
        return a * b + c;
    }
}

2) Sub-Project FMA for Java 11 and better
public class FMA {
    public static float fma(float a, float b, float c) {
        return Math.fma(a, b, c);
    }

    public static double fma(double a, double b, double c) {
        return Math.fma(a, b, c);
    }
}

3) Main Project dependencies as per Java Version
dependencies {
    if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
        implementation project(':FMA8')
    } else {
        implementation project(':FMA')
    }
}

So the Main Project will be able to call FMA.fma(a, b, c) despite the
Java Version.

Best regards
Andreas
 

Reply via email to