title: Using Generics to return Dynamic JAXBElement
body: <p>I have multiple root elements and thus, I need to write </p>
  
  <pre><code>JAXBElement&lt;BookType&gt; jaxbBookType = objectFactory.createBookType (bookType);
  JAXBElement&lt;OrderType&gt; jaxbOrderType = objectFactory.createOrderType (orderType);
  </code></pre>
  
  <p>and so on. I don't want to write this piece of code again and again. I am trying to write a method which will return me JAXBElement based on its input. </p>
  
  <p>What i am trying to write is</p>
  
  <pre><code>public &lt;T&gt; JAXBElement&lt;T&gt; getJaxbElement (Object obj){
      if (obj instanceof OrderType){
          return objectFactory.createOrderType((OrderType)obj);
      }
  }
  </code></pre>
  
  <p>But obviously, I am doing it wrong. Since i don't know much about Generics and after reading it for a while, I am still confuse. Can someone help me little bit here. </p>