Class JavaClassfileVersion

java.lang.Object
org.codehaus.plexus.languages.java.version.JavaClassfileVersion

public final class JavaClassfileVersion extends Object
Reads the bytecode of a Java class to detect the major, minor and Java version that was compiled.
Author:
Jorge Solórzano
  • Method Details

    • of

      public static JavaClassfileVersion of(byte[] bytes)
      Reads the bytecode of a Java class file and returns the JavaClassfileVersion.
      Parameters:
      bytes - byte[] of the Java class file
      Returns:
      the JavaClassfileVersion of the byte array
    • of

      public static JavaClassfileVersion of(Path path)
      Reads the bytecode of a Java class file and returns the JavaClassfileVersion.
      Parameters:
      path - Path of the Java class file
      Returns:
      the JavaClassfileVersion of the path java class
    • javaVersion

      public JavaVersion javaVersion()
      JavaVersion of the class file version detected.
      Returns:
      JavaVersion based on the major version of the class file.
    • majorVersion

      public int majorVersion()
      Returns the major version of the parsed classfile.
      Returns:
      the major classfile version
    • minorVersion

      public int minorVersion()
      Returns the minor version of the parsed classfile.
      Returns:
      the minor classfile version
    • isPreview

      public boolean isPreview()
      Returns if the classfile use preview features.
      Returns:
      true if the classfile use preview features.
    • toString

      public String toString()
      Returns a String representation of the Java class file version, e.g. 65.0 (Java 21).
      Overrides:
      toString in class Object
      Returns:
      String representation of the Java class file version
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object