title: Can I create read-only properties in Java?
body: <p>I'm creating a custom array class, and it has an <code>int</code> property <code>size</code>.</p>
  
  <p>This property is modified automatically if you do something like <code>add()</code> or <code>remove()</code>. I want to let the user read this property like <code>myArray.size</code>. However, making it <code>public</code> allows the user to change it, which doesn't make much sense for my class, and could break it.</p>
  
  <p>I could of course make it <code>private</code> and create a getter method <code>size()</code> and all's good. I don't have a problem with that, but still, is there a way to make a read-only property in Java?</p>
  
  <p>Looking around the web, I found this:</p>
  
  <ul>
  <li><a href="http://binkley.blogspot.com/2005/01/read-only-properties-in-java.html" rel="noreferrer">http://binkley.blogspot.com/2005/01/read-only-properties-in-java.html</a></li>
  </ul>
  
  <p>Their solution goes like</p>
  
  <pre><code>public final String title;
  </code></pre>
  
  <p>Which is tecnically valid, but that of course doesn't work for my array, since my property is not constant.</p>