Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you indicate any variable to be final, it means that you don't want the value it contains in the memory to change. In case of primitive types, that value represented by variables are the actual values. In case of object types, the values in memory are references to the object and not the actual objects.</p> <p>For example, you have:</p> <pre><code>final int x = 7; final Object y = new Object(); </code></pre> <p>You can think of the data being represented in memory this way:</p> <pre><code>+----------+----------+ | block | value | +----------+----------+ | 1001 | 7 | | 1002 | 2110 | +----------+----------+ </code></pre> <p>For the sake of discussion, let's leave out the details of how Java actually manages memory (because I don't know much about it either). So, in the example above, block 1001 is represented by variable x, and 1002 by y. Both are final variables which means that the values they represent cannot be changed. In the case of x, it's 7, which is the actual value, but in case of y, 2110 is just a reference to another memory location. Both cannot change but the reason primitive type variables become <em>constants</em> is that they represent actual values. But actually, you can say the same for object type variables too only that the <em>constants</em> they represent are references. So the <em>final</em> keyword is pretty much consistent in this regard.</p> <p>So, with final variables, if they're primitive types, they will constantly represent any particular values you set them to. If they're object/reference types, they will constantly point to any object you point them to (regardless of the objects' mutability).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload