1 16 17 package org.springframework.core; 18 19 30 public abstract class JdkVersion { 31 32 35 public static final int JAVA_13 = 0; 36 37 40 public static final int JAVA_14 = 1; 41 42 45 public static final int JAVA_15 = 2; 46 47 50 public static final int JAVA_16 = 3; 51 52 55 public static final int JAVA_17 = 4; 56 57 58 private static final String javaVersion; 59 60 private static final int majorJavaVersion; 61 62 static { 63 javaVersion = System.getProperty("java.version"); 64 if (javaVersion.indexOf("1.7.") != -1) { 66 majorJavaVersion = JAVA_17; 67 } 68 else if (javaVersion.indexOf("1.6.") != -1) { 69 majorJavaVersion = JAVA_16; 70 } 71 else if (javaVersion.indexOf("1.5.") != -1) { 72 majorJavaVersion = JAVA_15; 73 } 74 else if (javaVersion.indexOf("1.4.") != -1) { 75 majorJavaVersion = JAVA_14; 76 } 77 else { 78 majorJavaVersion = JAVA_13; 80 } 81 } 82 83 84 90 public static String getJavaVersion() { 91 return javaVersion; 92 } 93 94 104 public static int getMajorJavaVersion() { 105 return majorJavaVersion; 106 } 107 108 117 public static boolean isAtLeastJava14() { 118 return getMajorJavaVersion() >= JAVA_14; 119 } 120 121 130 public static boolean isAtLeastJava15() { 131 return getMajorJavaVersion() >= JAVA_15; 132 } 133 134 } 135 | Popular Tags |