title: Implement a final def within some trait where type parameters may or may not be the same
body: <p>Some setup before my question:</p>
  
  <pre><code>/* roughly equivalent to a union type */
  sealed trait NewType
  
  object NewType {
    final case class Boolean(record: Boolean) extends NewType
    final case class Long(record: Long) extends NewType
    final case class String(record: String) extends NewType
  }
  
  
  /* Try to convert a record of type T to a NewType */
  sealed trait NewTypeConverter[T] { def apply(record: T): Option[NewType] }
  
  object NewTypeConverter {
    trait BooleanConverter[T] extends NewTypeConverter[T] {
      override def apply(record: T): Option[NewType.Boolean]
    }
  
    trait LongConverter[T] extends NewTypeConverter[T] {
      override def apply(record: T): Option[NewType.Long]
    }
  
    trait StringConverter[T] extends NewTypeConverter[T] {
      override def apply(record: T): Option[NewType.String]
    }
  }
  </code></pre>
  
  <p>I want to define a trait <code>Data</code> like the following:</p>
  
  <pre><code>trait Data[T] {
    def name: String
    def converter: NewTypeConverter[_]
    final def value(record: T): Option[NewType] = ??? // calls converter
  }
  </code></pre>
  
  <p><strong>How can I implement this <code>final def value(record: T): Option[NewType]</code>?</strong></p>
  
  <p>A few things to note:</p>
  
  <ul>
  <li>The return type from the <code>apply</code> method of <code>converter</code> must be the same return type as <code>value</code>. So, if you happen to have a <code>BooleanConverter</code>, then <code>value</code> must return an <code>Option[NewValue.Boolean]</code>.</li>
  <li>Input type <code>T</code> to the <code>Data</code> trait does not have to be the same as the input type <code>_</code> to the <code>converter</code>. If they happen to be the same type, then the implementation could just be <code>final def value(record: T): Option[NewType] = converter(record)</code>. The trickier case is in when the input types differ. Let's say the input type to <code>Data</code> was a <code>String</code>, but the input type to <code>converter</code> was a <code>Long</code>. How would that be handled?</li>
  </ul>