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

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -