Advertisement

04.18.2008 at 05:51AM PDT, ID: 23333963
[x]
Attachment Details

Question about Generics

Asked by brunoguimaraes in Java Programming Language

Tags: Java

Hi,

I was wondering why the first method below can return an ArrayList, while the second one cannot.

    public <T> List<?> method1(List<T> type) {

        System.out.println(type);
        return new ArrayList<String>();
    }

    public <T> List<T> method2(List<T> type) {

        System.out.println(type);
        return new ArrayList<String>();
    }

Thanks!Start Free Trial
[+][-]04.18.2008 at 05:56AM PDT, ID: 21385309

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: Java
Sign Up Now!
Solution Provided By: cmalakar
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.18.2008 at 06:02AM PDT, ID: 21385335

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.18.2008 at 06:04AM PDT, ID: 21385352

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628