"CONST" in java
<p>I have a question about "CONST" in java.</p>

<p>I want to know how to make like "const struct VAL &amp;getVal()" in C-Language.</p>

<p>Here is sample code.</p>

<pre><code>public class test {
   /* VAL is just structure-like class */
   class VAL {
    public int i;
   };
   private VAL  val;

   /* test class functions */
   test() {
    val = new VAL();
    val.i = 1;
   }

   VAL getVal() {
    return val;
   }

   /* main function */
   public static void main(String[] args) {
    test t = new test();
    VAL  t_val;

    t_val = t.getVal();

    t_val.i = 2; /* it should be error if t_val variable is a const */
    System.out.printf("%d %d\n", t.getVal().i, t_val.i);
   }
}
</code></pre>

<p>below is C sample code.</p>

<pre><code>struct VAL
{
    int i;
};

const struct VAL &amp;getVal() /* THIS IS WHAT I WANT */
{
    static VAL xxx;
    return xxx;
}

int main()
{
    const VAL &amp;val = getVal();
    val.i = 0; /* error */

    VAL val2 = getVal();
    val2.i = 0; /* it's not an error, but it's ok because it cannot be changed xxx variable in getVal() either. */

    return 0;
}
</code></pre>
