Java Package - isCompatibleWith() Method
The java.lang.Package.isCompatibleWith() method is used to compare this package's specification version with a desired version. It returns true if this packages specification version number is greater than or equal to the desired version number.
Version numbers are compared by sequentially comparing corresponding components of the desired and specification strings. Each component is converted as a decimal integer and the values compared. If the specification value is greater than the desired value true is returned. If the value is less false is returned. If the values are equal the period is skipped and the next pair of components is compared.
Syntax
public boolean isCompatibleWith(String desired) throws NumberFormatException
Parameters
desired |
Specify the version string of the desired version. |
Return Value
Returns true if this package's version number is greater than or equal to the desired version number.
Exception
Throws NumberFormatException, if the desired or current version is not of the correct dotted form.
Example:
In the example below, the java.lang.Package.isCompatibleWith() method is used to check this package's specification version with version 1.7.
import java.lang.*; public class MyClass { public static void main(String[] args) { //create a java util package object Package p = Package.getPackage("java.util"); //check if this package specification //version with version 1.7 System.out.println(p.isCompatibleWith("1.7")); } }
The output of the above code will be:
true
❮ Java.lang - Package