This is called a "generic method", and you're just giving the type
signature of the method. Here's an example from our code.
public static <T extends Number & Comparable<T>> NumberField<T>
withMinimum(String id, T min) {
NumberField<T> f = new NumberField<T>(id);
f.add(new MinimumValidator<T>(min));
return f;
}
Which allows:
NumberField<Integer> adultAge = NumberField.withMinimum("bar", 18);
NumberField<Float> rating = NumberField.withinRange("foo", 0.0, 5.0);
Scott
On Thu, Jul 28, 2011 at 11:55 PM, Wilhelmsen Tor Iver
<[email protected]> wrote:
>> public <W> IWrapModel<W> wrapOnInheritance(Component component,Class<W>
>> type)
>
> The Class<W> parameter is only needed if you intend to do "new W();" or the
> like in the method (the Class is then something the compiler can grab hold of
> for calling the constructor). For just passing the type parameter to other
> generic classes it is not needed. The compiler sees the context (i.e. the
> left-hand side of an assignment) and if it cannot determine the type it will
> say "needs a cast" as a warning, but the code will compile since it's all
> Object anyway.
>
> - Tor Iver
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]