Home / Type/ JavaVersion Type — spring-boot Architecture

JavaVersion Type — spring-boot Architecture

Architecture documentation for the JavaVersion type/interface in JavaVersion.java from the spring-boot codebase.

Entity Profile

Source Code

core/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java lines 43–166

public enum JavaVersion {

	/**
	 * Java 17.
	 * @since 2.5.3
	 */
	SEVENTEEN("17", Console.class, "charset"),

	/**
	 * Java 18.
	 * @since 2.5.11
	 */
	EIGHTEEN("18", Duration.class, "isPositive"),

	/**
	 * Java 19.
	 * @since 2.6.12
	 */
	NINETEEN("19", Future.class, "state"),

	/**
	 * Java 20.
	 * @since 2.7.13
	 */
	TWENTY("20", Class.class, "accessFlags"),

	/**
	 * Java 21.
	 * @since 2.7.16
	 */
	TWENTY_ONE("21", SortedSet.class, "getFirst"),

	/**
	 * Java 22.
	 * @since 3.2.4
	 */
	TWENTY_TWO("22", Console.class, "isTerminal"),

	/**
	 * Java 23.
	 * @since 3.2.9
	 */
	TWENTY_THREE("23", NumberFormat.class, "isStrict"),

	/**
	 * Java 24.
	 * @since 3.4.3
	 */
	TWENTY_FOUR("24", Reader.class, "of", CharSequence.class),

	/**
	 * Java 25.
	 * @since 3.5.7
	 */
	TWENTY_FIVE("25", Reader.class, "readAllLines"),

	/**
	 * Java 26.
	 * @since 4.0.3
	 */
	TWENTY_SIX("26", String.class, "equalsFoldCase", String.class);

	private final String name;

	private final boolean available;

	private final Class<?> versionSpecificClass;

	JavaVersion(String name, Class<?> versionSpecificClass, String versionSpecificMethod, Class<?>... paramTypes) {
		this.name = name;
		this.versionSpecificClass = versionSpecificClass;
		this.available = ClassUtils.hasMethod(versionSpecificClass, versionSpecificMethod, paramTypes);
	}

	@Override
	public String toString() {
		return this.name;
	}

	/**
	 * Returns the {@link JavaVersion} of the current runtime.
	 * @return the {@link JavaVersion}
	 */
	public static JavaVersion getJavaVersion() {
		List<JavaVersion> candidates = Arrays.asList(JavaVersion.values());
		Collections.reverse(candidates);
		for (JavaVersion candidate : candidates) {
			if (candidate.available) {
				return candidate;
			}
		}
		return SEVENTEEN;
	}

	/**
	 * Return if this version is equal to or newer than a given version.
	 * @param version the version to compare
	 * @return {@code true} if this version is equal to or newer than {@code version}
	 */
	public boolean isEqualOrNewerThan(JavaVersion version) {
		return compareTo(version) >= 0;
	}

	/**
	 * Return if this version is older than a given version.
	 * @param version the version to compare
	 * @return {@code true} if this version is older than {@code version}
	 */
	public boolean isOlderThan(JavaVersion version) {
		return compareTo(version) < 0;
	}

	static class Hints implements RuntimeHintsRegistrar {

		@Override
		public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
			for (JavaVersion javaVersion : JavaVersion.values()) {
				hints.reflection().registerType(javaVersion.versionSpecificClass);
			}
		}

	}

}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free