title: What is the best way to implement "redefined" attribute in Java?
body: <p>Thank you in advance for reading.</p>
  
  <p>The "redefined" I'm talking about is the concept in UML Specification which is widely used.</p>
  
  <p><strong>My understanding is that:</strong> a "redefined" attribute's type is the subclass of the "redefining" attribute's type. While the owner of "redefined" attribute is the subclass of the owner of "redefining" attribute.</p>
  
  <p><strong>Given following example:</strong></p>
  
  <pre><code>Duration extends ValueSpecification
  DurationInterval extends Interval
  Interval has two attributes typed by ValueSpecification, min and max;
  DurationInterval has two "redefined" attributes typed by Duration, min and max;
  </code></pre>
  
  <p><strong>Here is my implementation:</strong></p>
  
  <p>1) If I define min/max in DurationInterval, I'm <strong>hiding another field</strong>; Actually, this is the easiest way to implement a "redefined" attribute. Anyone vote for this kind of implementation?</p>
  
  <pre><code>public Duration min/max;
  </code></pre>
  
  <p>2) Then I introduced the "Getter", great, the <a href="http://docs.oracle.com/javase/tutorial/java/IandI/override.html" rel="nofollow">Oracle</a> described "covariant return type" so this way works.
  However, I have to cast the type downward to make it work.</p>
  
  <p>3) For the "Setters" however, if I add "@Override", I will get error. I think this is arguable; Firstly, I have to admit that Oracle said explicitly that this is not override. Secondly, I think it is "Override" just Oracle didn't implement it yet. Am I wrong because I don't know the reason they do in this way?</p>
  
  <p>4) What's your implementation on UML's Re-defined attribute?</p>
  
  <pre><code>public class RedefineProj {
      static class ValueSpecification{}
      static class Duration extends ValueSpecification{}
      static class Interval{
          public ValueSpecification min;
          public ValueSpecification max;
  
          public ValueSpecification getMin(){
              return min;
          }
          public ValueSpecification getMax(){
              return max;
          }
          public void setMin(ValueSpecification min_){
              min = min_;
          }
          public void setMax(ValueSpecification max_){
              max = max_;
          }
      }
      static class DurationInterval extends Interval{
          @Override
          public Duration getMin(){
              return (Duration) min;
          }
          @Override
          public Duration getMax(){
              return (Duration)max;
          }
          public void setMin(Duration min_){
              min = min_;
          }
          public void setMax(Duration max_){
              max = max_;
          }
      }
  
      public static void main(String[] args) {
          // TODO code application logic here
          Interval i = new Interval();
          ValueSpecification v = i.getMax();
  
          DurationInterval di = new DurationInterval();
          Duration d = di.getMax();
      }
  }
  </code></pre>