How can I return either read-only access to a returned variable, or write access to it?
<p>In below class, <code>Store</code> class has exactly 1 <code>fruit</code> as a field variable. </p>

<p>I want <code>Store</code> class to do the following two things. One is returning the fruit's data only with read access, and the other is returning the fruit's data with the write access. The data returned has type <code>ByteBuffer</code>.</p>

<p>For example, if someone get the <code>ByteBuffer</code> through <code>getRead</code>, I don't want ByteBuffer to be modified at all. However, if someone access <code>ByteBuffer</code> through <code>getWrite</code>, then I am allowing him to modify the contents of memory pointed by ByteBuffer. </p>

<pre><code>class Fruit {
    private ByteBuffer data;
    public ByteBuffer getData(){
        return data;
    }
}
class Store {
    Fruit p;
    public ByteBuffer getRead(){
        return p.getData();
    }

    public ByteBuffer getWrite(){
        return p.getData();
    }
}
</code></pre>

<p>Is there anyway that I can control this access privilege in Java when I am using ByteBuffer? Or, should I have 2 variables in <code>Fruit</code> class that has the same value but does the different thing?</p>
