Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inferred type does not conform to upper bound(s)

Tags:

java

java-8

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?

like image 635
Jeffrey Tai Avatar asked Dec 02 '14 09:12

Jeffrey Tai


1 Answers

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;
}
like image 161
Eran Avatar answered Oct 15 '22 11:10

Eran