I am doing a project in which I have to negate the pixels of a PPM file (image).
I implemented my negative 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); }
The neg(maxColorVal) function is defined as follows:
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 to the map () function. What am I doing wrong?
source share