[Proposal]
Sean Fritz
Sean_member at pathlink.com
Tue Jun 20 14:29:42 PDT 2006
In article <e747sa$nn9$1 at digitaldaemon.com>, Dave says...
>
>So let's say we want to implement a generic sqr method in Java... How
>would we do it? I came up w/ this after just a quick look at the spec.
>to get the syntax right:
>
>public class Test
>{
> public static <T> T sqr(T x)
> {
> return x * x;
> }
>}
Java Generics are typesafe, you must bound the type with something that
implements multiply().
public class Test {
public static <T extends Multiplyable<T>> T sqr(T x) {
return x.multiply(x);
}
}
Assuming multiplyable is a generic interface that takes a type paramter.
More information about the Digitalmars-d
mailing list