Inheritance at compilation time?

Asked

Viewed 122 times

5

I was reviewing some codes and some concepts when I find the following assertive:

The legacy mechanism in Java occurs at compile time, i.e., every reuse of code accomplished by inheritance is immutable in running time

I spent a lot of time trying to understand the concept, but I confess that I could not understand, how so immutable in execution time? Is it correct that Java heritage occurs at compile time? I always thought it was runtime.

  • 4

    Once the inheritance is defined in the code, nor can the JVM remake that relation. So, when it executes, it does not change; it is "immutable" in "runtime"

1 answer

11


Once defined the "low plant" type (class) You can’t change anything inside him. Then the whole model is fixed for the entire run time, each field, method field, each type definition detail cannot be changed. And all objects that are instantiated from this model will always be identical, is guaranteed.

This is in contrast to dynamic languages where it is possible to change the composition of the model or specific objects during execution, which gives flexibility, but there is a loss of performance and robustness in the code, since it takes a whole treatment to deal with this situation, optimizations are not possible because you do not know what you will find there, and at every moment you may have a surprise.

Heritage in Java is something conceptual, it occurs in the model and not in the object, so you inherit one model in another that you’re modeling now.

If you change the code and recompile the inheritance or the entire composition of each class you can assemble different and the next execution will have the differences included.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.