java - Difference between wildcard type vs bounded type -


public static void main(string args[]) {     list<double> doublelist = new arraylist<>();     doublelist.add(new double(101.215d));     doublelist.add(new double(102.215d));     doublelist.add(new double(103.215d));      printintvalue1(doublelist);     system.out.println("*******");     printintvalue2(doublelist); }   //bounded parameter public static <t extends number> void printintvalue1(list<t> list){     for(t num : list){         system.out.println(num.intvalue());     } } //wildcard parametr public static  void printintvalue2(list<? extends number> list){     for(number num : list){         system.out.println(num.intvalue());     } } 

as in above 2 methods, both gives same results. can tell me if work done bounded type why concept of wildcard there? wildcard other work bounded types don't?

i think perspective of example, there little benefit gained using wildcards. believe, however, wildcards introduced support assignments (or related constructs) of generic types using related type parameters.

consider:

list<number> numberlist = new arraylist<double>(); //won't compile 

contrast to:

list<? extends number> anynumberlist = null; anynumberlist = new arraylist<double>(); anynumberlist = new arraylist<integer>(); 

the second snippet valid code.

i agree that, when seen method parameter type perspective, wildcard type doesn't present considerably particular advantages.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -