1

i am feeling so noob right now asking this question, but i cannot figure it out what it's going on

import java.util.List;
public class ListResponse<T> {

    private List<T> items;
    private Paging paging;

    public <T> ListResponse(List<T> items, Paging paging) {
        this.items = **items**;
        this.paging = paging;
    }

}

I am getting a compiler error on that items parameter that i marked. The error is:

Type mismatch: cannot convert from java.util.List<T> to java.util.List<T>

Do you have any idea what is happening ? Thanks!

2
  • ListResponse is not a void method, shouldn't it have return value? Commented Mar 17, 2015 at 15:42
  • @Apurva, it's a constructor. Commented Mar 17, 2015 at 15:42

1 Answer 1

4

The <T> that is defined as constructor-scope, hides the class-scoped <T> and the compiler treats these as different types. That's why you get a compile-time error.

Just get rid of the constructor's type parameter:

public ListResponse(List<T> items, Paging paging) {
    this.items = items;
    this.paging = paging;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.