title: Getters on an immutable type
body: <p>I am writing some immutable types in Java and wonder about how to name the accessor methods.
  The Java Bean specification says that the names of accessors should be getX or isX, but since the fields are final, there is no setter and the fields are more like attributes than properties.</p>
  
  <p>There for I'd prefer naming the getter methods like:</p>
  
  <pre><code>public T x()
  </code></pre>
  
  <p>rather than</p>
  
  <pre><code>public T getX()
  </code></pre>
  
  <p>Please note as an example:</p>
  
  <pre><code>public int java.lang.String#length()
  </code></pre>
  
  <p>(Which might have been specified so early in the Java history, so the conventions where not there yet.)</p>
  
  <p>The immutable objects expose means to create modified versions of themselves through methods which I've tried to name like a verb rather than <code>MyObject MyObject#setX()</code>, this should limit the risk of the user calling setX() and think that the object has changed. So: <code>MyObject MyObject#shine(newShineLevel)</code>.</p>
  
  <p>This is not always possible easy though. How would you name a method for adjusting an endpoint in a rectangle other than <code>Rectangle.setUpperLeft()</code>? <code>Rectangle.adjustUpperLeft</code> maybe, but now we're just moving away from the conventions.</p>
  
  <p>I guess the question is relevant for all languages, but this questions concern Java in particular.</p>