Swapping out superclass with class of same pkg, name, methods?
Hey there. Consider two classes with the same package, same name, and same methods (params included). Let's call these classes Class A1 and Class A2. Secondly, consider a class, Class X, that extends Class A1.The class loader will only have contain Class A1 or Class A2. Could I replace Class A1 with Class A2 without interruption? I've tested this scenario with success. But, does this violate the JL or VM specs? Could behavior be different across JVMs? Other issues?
Thanks.
-Chris
[505 byte] By [
cwallcaa] at [2007-10-2 23:24:37]

Let me provide a little more context.
Class A1 extends Class Y and resides in JVM 1.
Class A2 extends Class Z and resides in JVM 2.
Class X was originally compiled extending Class A1 and runs in JVM 1.
Again, Class A2 has the same package name, class name, and methods as Class A1, but has a different implementation.
What are the consequences, if any, if I move Class X to JVM 2?
Thanks.
Tell me if I understand this question correctly: You have built Y, A1, and X in the same compilation environment, and you know that JVM1 runs them correctly. Now you want to run JVM 2, loading Z, A2, and X. Since X's classfile is not recompiled specifically for Z and A2, you want to know what guarantees apply.
If it were C++ instead of Java, few if any would apply, since the C++ compiler routinely incorporates information from Z and A2 into the binary of X, in analogous situations.
In Java, you should be all right. You are right in emphasizing that the package, class, and method sets are compatible. The method signatures should be identical also.
The only thing Java compilation inlines are constants (final member variables with constant initializer expressions). If Z, Y, A[12] do not export constant definitions, you should be fine.
Here are some documentation links that give the details:
JLS 13, Binary Compatibility:
13.4.4 Superclasses and Superinterfaces
http://java.sun.com/docs/books/jls/third_edition/html/binaryComp.html#13.4.4
13.4.9 final Fields and Constants
http://java.sun.com/docs/books/jls/third_edition/html/binaryComp.html#13.4.9
jrosea at 2007-7-14 16:03:25 >
