0
votes

Let’s say that in hypothetical Java version X.1 we have a class in the standard library (or third-party with backwards compatible API and version tied to Java version)

public class String {
    private final byte[] bytes;
    //...
}

and in Java X.2 it has changed internally

public class String {
    private final char[] chars;
    //...
}

We also have a class that accesses String class field, which is a part of a plugin for a server

public class Accessor {
    public static Field getField() throws ReflectiveOperationException {
        return String.class.getDeclaredField(“bytes”);
}

Server runs on Java X.2, plugin was compiled using Java X.1 and loaded at runtime

What will happen? Which String class will the Accessor see? If it will be X.1 then what happens if server and plugin share a String? If it will be X.2 is there a way to force a specific version at compile-time or in the package configuration, or at least determine from which Java version the currently visible String class comes from?

1

1 Answers

0
votes

If we talk about java.lang.String class or any other class from jvm then it is usually a part of a JVM where the code is run. And in your case you'll get version x.2.

But if we talk about custom compiled class from a 3rd party library then it depends on the target version that was specified during compilation of that class. In your case it might be version 1.x.