推断类型不符合上限

Jef*_*Tai 8 java java-8

我正在做一个项目,我必须否定PPM文件(图像)的像素.

我实现了我的否定函数:

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);
}
Run Code Online (Sandbox Code Playgroud)

neg(maxColorVal)函数被定义为这样的:

public void neg(int maxColorVal) 
{
    R = maxColorVal - R;
    G = maxColorVal - G;
    B = maxColorVal - B;
}
Run Code Online (Sandbox Code Playgroud)

当我编译代码时,我收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

map()函数的错误点.我做错了什么?

Era*_*ran 4

更正:

你的map函数需要一个返回某种引用类型的方法,但neg有一个void返回类型。

尝试将您的neg方法更改为:

public RGB neg(int maxColorVal) {
    R = maxColorVal - R;
    G = maxColorVal - G;
    B = maxColorVal - B;
    return this;
}
Run Code Online (Sandbox Code Playgroud)