title: Scala - Create a new Class on runtime based on dynamic data
body: <p>I have an array of String which I will be receiving from an arbitrary function. I want to use the elements of the array to create a new class at runtime (not a new object of an existing class). Let me give you an example</p>
  
  <pre><code>val keyCounts = Array[String]
  
  def newDomainPartioner(keyCounts : Array[Strings]) : DomainPartitioner{
      return class DomainPartitioner with Serializable {
          def getPartition(key: Any): Int = key match {
  
            case &lt;first element of keyCount&gt; =&gt; 
              1
            case &lt;second element of keyCount&gt; =&gt;
              1
            case &lt;third element of keyCount&gt; =&gt;  
              1
            case &lt;forth element of keyCount&gt; =&gt; 
              1
            case _ =&gt; 0
          }
  
        }
  }
  </code></pre>
  
  <p>Is there a way to achieve the intended functionality ?</p>