jscherman
jscherman

Reputation: 6179

compiler error converting java.util.list to java.util.list?

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!

Upvotes: 1

Views: 365

Answers (1)

Konstantin Yovkov
Konstantin Yovkov

Reputation: 62864

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;
}

Upvotes: 4

Related Questions