Inferred type does not conform to upper bound(s)

java, java-8

Solution

Correction :

Your `map` function expects a method that returns some reference type, but `neg` has a `void` return type.

Try to change your `neg` method to :

public RGB neg(int maxColorVal) {
    R = maxColorVal - R;
    G = maxColorVal - G;
    B = maxColorVal - B;
    return this;
}

Problem

I'm doing a project in which I have to negate the pixels of a PPM file (image). I implemented my negate function as such: ``` public PPMImage negate() { RGB[] negated = new RGB[pixels.length]; System.arraycopy(pixels, 0, negated, 0, pixels.length); RGB[] negatedArr = Arrays.stream(negated).parallel().map(rgb -> rgb.neg(maxColorVal)).toArray(size -> new RGB[size]); return new PPMImage(width, height, maxColorVal, negatedArr); } ``` With the `neg(maxColorVal)` function being defined as this: ``` public void neg(int maxColorVal) { R = maxColorVal - R; G = maxColorVal - G; B = maxColorVal - B; } ``` When I compile the code, I get the following error: ``` error: incompatible types: inferred type does not conform to upper bound(s) RGB[] negatedArr = Arrays.stream(negated).parallel().map(rgb -> rgb.neg(maxColorVal)).toArray(size -> new RGB[size]); inferred: void upper bound(s): Object ``` The error points at the map() function. What am I doing incorrectly?

Original source