1

I am playing around with the new Lambdas in Java 8 in Android Studio and attempting to utilize the below line:

public Contact findContactByCode(String ContactCode) {
    return this.list.stream().filter(o -> o.getType().getCode() == ContactCode).collect(Collectors.toList());
}

The list object is a generic ArrayList, for which the generic type has been assigned to the Contact Model. Everything is good until I get to the collection function and that is where I am getting the below error:

"no instance of variable T exists so that List< T > conforms to Contact, inference variable R has incompatible bounds: Equality constraints: List< T >, Upper bounds: Object, Contact"

Everything that I am seeing looks correct, but I am not quite sure what is going wrong.

4
  • 4
    What are you assigning the return value of collect() to? Commented Sep 29, 2017 at 17:23
  • 2
    Please post few more lines of your code including instantiation of the array list. Commented Sep 29, 2017 at 17:35
  • Indra Basak, I have include the entire function. Which is not much. Commented Sep 30, 2017 at 13:46
  • Contact is not a List. Change the method to return List<Contact> Commented Sep 30, 2017 at 13:50

1 Answer 1

1

You are attempting to return a List, but the method declaration calls for returning a Contact. Change one of those and you should be fine

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.