Source (Java):

 

class foo {

static <T> void fromArrayToCollection(T[] a, Collection<T> c) {

     for (T o : a) {

         c.add(o);

     }

}

void demo() {

     String[] sa = new String[100];

     Collection<String> cs = new ArrayList<String>();

     fromArrayToCollection(sa, cs);// T inferred to be String

     }

}

 

<?xml version="1.0" encoding="UTF-8"?>
<kdm:Segment xmi:version="2.1"

xmlns:xmi="http://www.omg.org/XMI"

xmlns:action="http://kdm.omg.org/action"

xmlns:code="http://kdm.omg.org/code"

xmlns:kdm="http://kdm.omg.org/kdm"

name="Template Example">
 
<model xmi:id="id.0" xmi:type="code:CodeModel">
    <codeElement xmi:id="id.1" xmi:type="code:ClassUnit" name="foo">
      <codeElement xmi:id="id.2" xmi:type="code:TemplateUnit" name="fromArrayToCollection&lt;T>">
        <codeElement xmi:id="id.3" xmi:type="code:TemplateParameter" name="T"/>
       
<codeElement xmi:id="id.4" xmi:type="code:MethodUnit" name="fromArrayToCollection" type="id.6">
          <entryFlow xmi:id="id.5" to="id.14" from="id.4"/>
         
<codeElement xmi:id="id.6" xmi:type="code:Signature">
           
<parameterUnit xmi:id="id.7" name="a">
             
<codeElement xmi:id="id.8" xmi:type="code:ArrayType">
               
<itemUnit xmi:id="id.9" type="id.3"/>
              </codeElement>
            </parameterUnit>
            <parameterUnit xmi:id="id.10" name="c" type="id.11">
             
<codeElement xmi:id="id.11" xmi:type="code:TemplateType" name="Collection&lt;T1>">
               
<codeRelation xmi:id="id.12" xmi:type="code:ParameterTo" to="id.3" from="id.11"/>
                <codeRelation xmi:id="id.13" xmi:type="code:InstanceOf" to="id.75" from="id.11"/>
              </codeElement>
            </parameterUnit>
          </codeElement>
          <codeElement xmi:id="id.14" xmi:type="action:ActionElement" name="a1" kind="Compound">
            <codeElement xmi:id="id.15" xmi:type="action:ActionElement" name="a1.1" kind="Call">
              <actionRelation xmi:id="id.16" xmi:type="action:Addresses" to="id.7" from="id.15"/>
              <actionRelation xmi:id="id.17" xmi:type="action:Calls" to="id.81" from="id.15"/>
              <actionRelation xmi:id="id.18" xmi:type="action:Flow" to="id.19" from="id.15"/>
            </codeElement>
            <codeElement xmi:id="id.19" xmi:type="action:ActionElement" name="a1.2" kind="Call">
              <codeElement xmi:id="id.20" xmi:type="code:StorableUnit" name="t1" type="id.88" kind="register"/>
              <actionRelation xmi:id="id.21" xmi:type="action:Addresses" to="id.40" from="id.19"/>
              <actionRelation xmi:id="id.22" xmi:type="action:Calls" to="id.83" from="id.19"/>
              <actionRelation xmi:id="id.23" xmi:type="action:Writes" to="id.20" from="id.29"/>
              <actionRelation xmi:id="id.24" xmi:type="action:Flow" to="id.25" from="id.19"/>
            </codeElement>
            <codeElement xmi:id="id.25" xmi:type="action:ActionElement" name="1.3" kind="Condition">
              <actionRelation xmi:id="id.26" xmi:type="action:Reads" to="id.20" from="id.25"/>
              <actionRelation xmi:id="id.27" xmi:type="action:TrueFlow" to="id.29" from="id.25"/>
              <actionRelation xmi:id="id.28" xmi:type="action:FalseFlow" to="id.39" from="id.25"/>
            </codeElement>
            <codeElement xmi:id="id.29" xmi:type="action:ActionElement" name="a1.4" kind="Call">
              <actionRelation xmi:id="id.30" xmi:type="action:Addresses" to="id.40" from="id.29"/>
              <actionRelation xmi:id="id.31" xmi:type="action:Calls" to="id.82" from="id.29"/>
              <actionRelation xmi:id="id.32" xmi:type="action:Writes" to="id.44" from="id.29"/>
              <actionRelation xmi:id="id.33" xmi:type="action:Flow" to="id.34" from="id.29"/>
            </codeElement>
            <codeElement xmi:id="id.34" xmi:type="action:ActionElement" name="a1.5" kind="Call">
              <actionRelation xmi:id="id.35" xmi:type="action:Addresses" to="id.10" from="id.34"/>
              <actionRelation xmi:id="id.36" xmi:type="action:Reads" to="id.44" from="id.34"/>
              <actionRelation xmi:id="id.37" xmi:type="action:Calls" to="id.84" from="id.34"/>
              <actionRelation xmi:id="id.38" xmi:type="action:Flow" to="id.19" from="id.34"/>
            </codeElement>
            <codeElement xmi:id="id.39" xmi:type="action:ActionElement" name="1.6" kind="Nop"/>
            <codeElement xmi:id="id.40" xmi:type="code:StorableUnit" name="iter" type="id.41" kind="register">
              <codeElement xmi:id="id.41" xmi:type="code:TemplateType" name="Iterator&lt;T1>">
                <codeRelation xmi:id="id.42" xmi:type="code:InstanceOf" to="id.78" from="id.41"/>
                <codeRelation xmi:id="id.43" xmi:type="code:ParameterTo" to="id.3" from="id.41"/>
              </codeElement>
            </codeElement>
            <codeElement xmi:id="id.44" xmi:type="code:StorableUnit" name="o" type="id.3" kind="local"/>
            <actionRelation xmi:id="id.45" xmi:type="action:Flow" to="id.15" from="id.14"/>
          </codeElement>
        </codeElement>
      </codeElement>
      <codeElement xmi:id="id.46" xmi:type="code:MethodUnit" name="demo" type="id.47">
        <codeElement xmi:id="id.47" xmi:type="code:Signature"/>
        <codeElement xmi:id="id.48" xmi:type="code:StorableUnit" name="sa" type="id.49" kind="local">
          <codeElement xmi:id="id.49" xmi:type="code:ArrayType" name="ar2">
            <itemUnit xmi:id="id.50" type="id.89"/>
          </codeElement>
        </codeElement>
        <codeElement xmi:id="id.51" xmi:type="action:ActionElement" name="demo.1" kind="New">
          <codeElement xmi:id="id.52" xmi:type="code:Value" name="100" type="id.90"/>
          <actionRelation xmi:id="id.53" xmi:type="action:Reads" to="id.52" from="id.51"/>
          <actionRelation xmi:id="id.54" xmi:type="action:Creates" to="id.49" from="id.51"/>
          <actionRelation xmi:id="id.55" xmi:type="action:Writes" to="id.48" from="id.51"/>
          <actionRelation xmi:id="id.56" xmi:type="action:Flow"/>
        </codeElement>
        <codeElement xmi:id="id.57" xmi:type="code:StorableUnit" name="cs" type="id.58" kind="local">
          <codeElement xmi:id="id.58" xmi:type="code:TemplateType" name="Collection&lt;String>">
            <codeRelation xmi:id="id.59" xmi:type="code:ParameterTo" to="id.89" from="id.58"/>
            <codeRelation xmi:id="id.60" xmi:type="code:InstanceOf" to="id.75" from="id.58"/>
          </codeElement>
        </codeElement>
        <codeElement xmi:id="id.61" xmi:type="action:ActionElement" name="demo.2" kind="New">
          <codeElement xmi:id="id.62" xmi:type="code:TemplateType" name="ArrayList&lt;String>">
            <codeRelation xmi:id="id.63" xmi:type="code:ParameterTo" to="id.89" from="id.62"/>
            <codeRelation xmi:id="id.64" xmi:type="code:InstanceOf" to="id.85" from="id.62"/>
          </codeElement>
          <actionRelation xmi:id="id.65" xmi:type="action:Creates" to="id.62" from="id.51"/>
          <actionRelation xmi:id="id.66" xmi:type="action:Writes" to="id.57" from="id.61"/>
          <actionRelation xmi:id="id.67" xmi:type="action:Flow"/>
        </codeElement>
        <codeElement xmi:id="id.68" xmi:type="action:ActionElement" name="demo.3" kind="Call">
          <codeRelation xmi:id="id.69" xmi:type="code:InstanceOf" to="id.2" from="id.68"/>
          <codeRelation xmi:id="id.70" xmi:type="code:ParameterTo" to="id.89" from="id.68"/>
          <actionRelation xmi:id="id.71" xmi:type="action:Reads" to="id.48" from="id.68"/>
          <actionRelation xmi:id="id.72" xmi:type="action:Reads" to="id.57" from="id.68"/>
          <actionRelation xmi:id="id.73" xmi:type="action:Calls" to="id.4" from="id.68"/>
       
</codeElement>
      </codeElement>
    </codeElement>
    <codeElement xmi:id="id.74" xmi:type="code:LanguageUnit" name="Common Java datatypes">
      <codeElement xmi:id="id.75" xmi:type="code:TemplateUnit" name="Collection&lt;T>">
        <codeElement xmi:id="id.76" xmi:type="code:TemplateParameter" name="T"/>
        <codeElement xmi:id="id.77" xmi:type="code:ClassUnit" name="Collection"/>
      </codeElement>
      <codeElement xmi:id="id.78" xmi:type="code:TemplateUnit" name="Iterator&lt;T>">
        <codeElement xmi:id="id.79" xmi:type="code:TemplateParameter" name="T"/>
        <codeElement xmi:id="id.80" xmi:type="code:ClassUnit" name="Iterator">
          <codeElement xmi:id="id.81" xmi:type="code:MethodUnit" name="iterator" kind="constructor"/>
         
<codeElement xmi:id="id.82" xmi:type="code:MethodUnit" name="next"/>
          <codeElement xmi:id="id.83" xmi:type="code:MethodUnit" name="hasNext"/>
          <codeElement xmi:id="id.84" xmi:type="code:MethodUnit" name="add"/>
        </codeElement>
      </codeElement>
      <codeElement xmi:id="id.85" xmi:type="code:TemplateUnit" name="ArrayList&lt;T>">
        <codeElement xmi:id="id.86" xmi:type="code:TemplateParameter" name="T"/>
        <codeElement xmi:id="id.87" xmi:type="code:ClassUnit" name="ArrayList"/>
      </codeElement>
      <codeElement xmi:id="id.88" xmi:type="code:BooleanType" name="Boolean"/>
      <codeElement xmi:id="id.89" xmi:type="code:StringType" name="String"/>
      <codeElement xmi:id="id.90" xmi:type="code:IntegerType" name="Integer"/>
   
</codeElement>
  </model>
</kdm:Segment>