View RSS Feed

Advanced Java

Advanced Java programming.

  1. Java Generic's Wildcards

    by , 02-18-2012 at 04:57 PM
    Consider a situation where you desire all List elements to be printed. This could be explained by the given code:
    Java Code: This is the code to explain printing of all elements
    public void processElements(List<Object> elements){
       for(Object o : elements){
          System.out.println(o);
       }
    }
    This method couldn’t be used along with List<String> instance. To sort out this problem, wildcard operator is used. For writing generic List by the help of wildcard operator, use this code.
    ...
    Categories
    Generics