How to force java to accept the same type generic parameters -
i found following code snippet java™ tutorials type inference
static <t> t pick(t a1, t a2) { return a2; } serializable s = pick("d", new arraylist<string>()); so a1 , a2 can different type here, how can force them same type? pick("d", "e"); can called.
how can force them same type? if t specific type string, 1 can avoid generic. can restrict there scope, -
static <t extends number> t pick(t a1, t a2) { return a2; } pick(0, 1), t restricted number , sub classes. i've not draw example of <t extends string> string class final.
Comments
Post a Comment