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?
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With