-1

I have this class:

public class AirbnbListing {
...
private int price
...
public int getPrice() { return price; }

And I'm trying to use a java stream to collect the integer prices from an ArrayList of AirbnbListing objects:

ArrayList<AirbnbListing> properties = dataParser.getNeighbourhoodProperties(neighbourhood, 0, -1, 0, "All");
ArrayList<Integer> prices =
    properties.stream()
        .map(AirbnbListing::getPrice)
        .collect(Collectors.toList());

But I'm getting "Incompatiable types: inferenance variable R has incompatible bounds". Not sure what the issue is.

Arnaiz
  • 63
  • 2
  • 5

1 Answers1

0

Create ArrayList By passing argument like.

ArrayList<Integer> prices =
    properties.stream()
        .map(AirbnbListing::getPrice)
        .collect(Collectors.toCollection(ArrayList::new));//<------- this
Khalid Shah
  • 3,132
  • 3
  • 20
  • 39