shrini1000
shrini1000

Reputation: 7236

Brian Goetz on 'final' keyword

In this article: http://www.ibm.com/developerworks/java/library/j-jtp1029/index.html

Brian Goetz states: "Just because class X is compiled against final class Y doesn't mean that the same version of class Y will be loaded at run time."

Could someone please explain this in more detail? If class Y is final, it can't be subclassed, so what's the meaning of this statement?

Upvotes: 1

Views: 713

Answers (3)

allingeek
allingeek

Reputation: 1388

What is being stated is not that the class can be subclassed. But rather that you have no guarantee of the version of the built class that you are running against. You could make some change, recompile and swap the binaries out. Your code would run but it would be a different version.

Upvotes: 1

Greg Hewgill
Greg Hewgill

Reputation: 994281

Suppose you load a class X with a classloader that has a different implementation of class Y. In that case, X would be linked with the different Y.

Note that the statement says "the same version of class Y", which means Y could simply be changed after X was compiled.

Upvotes: 4

Peter
Peter

Reputation: 5798

If X is compiled against class Y thats in jar Z you can run class X with class V in jar W

its similar to compiling a class in java 1.5 but running it in 1.6

Upvotes: 1

Related Questions