Polymorphic copy: Difference between revisions

Content added Content deleted
(→‎{{header|Go}}: small update for library change)
No edit summary
Line 753: Line 753:
}
}
}</lang>
}</lang>

=={{header|NetRexx}}==
{{trans|Java}}
<lang NetRexx>/* NetRexx */
options replace format comments java crossref savelog symbols binary

-- -----------------------------------------------------------------------------
class RCPolymorphicCopy public

method copier(x = T) public static returns T
return x.copy

method main(args = String[]) public constant
obj1 = T()
obj2 = S()
System.out.println(copier(obj1).name) -- prints "T"
System.out.println(copier(obj2).name) -- prints "S"
return

-- -----------------------------------------------------------------------------
class RCPolymorphicCopy.T public implements Cloneable

method name returns String
return T.class.getSimpleName

method copy public returns T
dup = T

do
dup = T super.clone
catch ex = CloneNotSupportedException
ex.printStackTrace
end

return dup

-- -----------------------------------------------------------------------------
class RCPolymorphicCopy.S public extends RCPolymorphicCopy.T

method name returns String
return S.class.getSimpleName
</lang>


=={{header|Objective-C}}==
=={{header|Objective-C}}==