title: Scala : Hide two class behind a generic one
body: <p>I have two different scala class that we can call ClassA and ClassB.</p>
  
  <p>Let's also say that I have to function doSomething(ClassA) and doSomething(ClassB)</p>
  
  <p>I want to create a new class ClassC that can be construct either from a ClassA or a ClassB and implement a function doSomething.</p>
  
  <p>My problem is that I'm not really familiar with the Scala constructors (I'm more a Java developer) and I don't feel like what I am doing is right. Here is my try : </p>
  
  <pre><code>class ClassC(obj:Object,tmp:Integer) {
  
    def this(classA: ClassA){
      this(classA,0)
    }
  
    def this(classB: ClassB){
      this(classB,0)
    }
  
    def doSomething(){
      if(obj.getClass.getName == "ClassA"){
            // do something with obj
      }else if(obj.getClass.getName == "ClassB"){
            // do something with obj
      }
    }
  }
  </code></pre>