title: How to have multiple upper bounds for the generic type parameter of a function?
body: <p>There are an abstract class <code>Base</code> and a interface <code>BaseAction</code>. In my project, <code>A</code> and  <code>B</code> both implements <code>Base</code>, <code>BaseAction</code>.</p>
  <pre><code>abstract class Base {
      abstract fun doAction()
  }
  
  interface BaseAction {
  
  }
  
  class A: Base(), BaseAction {
      override fun doAction() {
  
      }
  }
  
  class B: Base(), BaseAction {
      override fun doAction() {
  
      }
  }
  </code></pre>
  <p>Now I define an abstract class <code>AbstractCommand</code> and there is a function:</p>
  <pre><code>abstract class AbstractCommand {
      abstract fun &lt;T&gt; getActions(): List&lt;T&gt; where T: Base, T: BaseAction
  
      fun doSomething() {
          // Here A and B both are Ok for me.
          getActions&lt;&gt;()
      }
  
  }
  </code></pre>
  <p>As you see, there are two upper bounds: <code>Base</code> and <code>BaseAction</code>. In function <code>doSomething</code>, I want to invoke <code>getActions</code>，in that List，class A and B both are ok for me.</p>
  <p><strong>My question is how I can invoke <code>getActions</code>.</strong></p>
  <h1>EDIT</h1>
  <p>Yes I can define T in class <code>AbstractCommand</code>, but if so, AbstractCommand only return List&lt;<code>A</code>&gt; or List&lt;<code>B</code>&gt;. However List is expected.</p>
  <h1>EDIT</h1>
  <p>It's my fault for my description. I must explain more about my question and explain it's not suitable to let A and B extends same parent directly.</p>
  <p>In fact, my question is more complex as describe above. Let me hold my full example.</p>
  <pre><code>abstract class Base {
      abstract fun doAction()
  }
  
  interface BuyGiftAction {
      abstract fun buyGift()
  }
  
  abstract class A: Base(){
      abstract fun doActionA()
  }
  
  abstract class B: Base() {
      abstract fun doActionB()
  }
  </code></pre>
  <p>As you see, A and B both extends Base class and define new abstract function. Now child of A want to implement <code>BuyGiftAction</code> and child of B does so.</p>
  <pre><code>class ChildA: A(), BuyGiftAction {
      override fun doActionA() {
      }
  
      override fun doAction() {
      }
  
      override fun buyGift() {
      }
  }
  
  class ChildB: B(), BuyGiftAction {
      override fun doActionB() {
      }
  
      override fun doAction() {
      }
  
      override fun buyGift() {
      }
  }
  </code></pre>
  <p>Obviously it's very not suitable to let <code>A</code> and <code>B</code> both extend a class named <code>Parent</code> who extends <code>Base</code> and implements <code>BuyGiftAction</code>.</p>
  <pre><code>abstract class AbstractCommand {
      abstract fun &lt;T&gt; getActionArray(): Array&lt;T&gt; where T: Base, T: BuyGiftAction
  
      fun doSomething() {
          // Here ChildA and ChildB both are Ok for me.
          getActionArray&lt;&gt;()
      }
  
  }
  </code></pre>
  <p><a href="https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS40LjEwIiwicGxhdGZvcm0iOiJqYXZhIiwiYXJncyI6IiIsImpzQ29kZSI6IiIsIm5vbmVNYXJrZXJzIjp0cnVlLCJ0aGVtZSI6ImlkZWEiLCJjb2RlIjoiYWJzdHJhY3QgY2xhc3MgQmFzZSB7XG4gICAgYWJzdHJhY3QgZnVuIGRvQWN0aW9uKClcbn1cblxuaW50ZXJmYWNlIEJ1eUdpZnRBY3Rpb24ge1xuICAgIGFic3RyYWN0IGZ1biBidXlHaWZ0KClcbn1cblxuYWJzdHJhY3QgY2xhc3MgQTogQmFzZSgpe1xuICAgIGFic3RyYWN0IGZ1biBkb0FjdGlvbkEoKVxufVxuXG5hYnN0cmFjdCBjbGFzcyBCOiBCYXNlKCkge1xuICAgIGFic3RyYWN0IGZ1biBkb0FjdGlvbkIoKVxufVxuXG5cbmNsYXNzIENoaWxkQTogQSgpLCBCdXlHaWZ0QWN0aW9uIHtcbiAgICBvdmVycmlkZSBmdW4gZG9BY3Rpb25BKCkge1xuICAgIH1cblxuICAgIG92ZXJyaWRlIGZ1biBkb0FjdGlvbigpIHtcbiAgICB9XG5cbiAgICBvdmVycmlkZSBmdW4gYnV5R2lmdCgpIHtcbiAgICB9XG59XG5cbmNsYXNzIENoaWxkQjogQigpLCBCdXlHaWZ0QWN0aW9uIHtcbiAgICBvdmVycmlkZSBmdW4gZG9BY3Rpb25CKCkge1xuICAgIH1cblxuICAgIG92ZXJyaWRlIGZ1biBkb0FjdGlvb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