The inferred type does not match the upper bounds (bounds)

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?

+5
source share
1 answer

Correction:

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

Try changing your neg method to:

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

Source: https://habr.com/ru/post/1208123/


All Articles