gpt4 book ai didi

java - 为什么这会导致错误 - Java 方法中的类

转载 作者:行者123 更新时间:2023-12-02 06:24:55 24 4
gpt4 key购买 nike

所以我想知道为什么会返回错误:“无法从 Compn 类型对非静态方法comparen(args) 进行静态引用”。我显然无法使方法 Comparen() 静态,所以不确定出了什么问题。

//8 bit comparison. bit 7 and bit 15 are highest.
public static boolean[] comparator(boolean bit0, boolean bit1, boolean bit2,
boolean bit3, boolean bit4, boolean bit5,
boolean bit6, boolean bit7,
boolean bit8, boolean bit9, boolean bit10,
boolean bit11, boolean bit12, boolean bit13,
boolean bit14, boolean bit15) {

boolean[] comparatorOUT = new boolean[3]; //0 == A>B, 1 == B>A, 2 == A==B
boolean[][] currVal = new boolean[16][3]; // [0] = highest bit.

class Compn {
boolean[] comparen(boolean curr1, boolean curr2, boolean curr3, boolean b1, boolean b2) {
boolean[] storage = new boolean[3];
storage[0] = curr3 && (((!xor(curr1, curr2) && b1) && !(!xor(curr1, curr2) && b2)) || curr1 && !curr2);
storage[1] = curr3 && (((!xor(curr1, curr2) && b2) && !(!xor(curr1, curr2) && b1)) || !curr1 && curr2);
storage[2] = curr3 && (!storage[0] && !storage[1]);
return storage;
}
}
currVal[0] = Compn.comparen(false, false, true, bit7, bit15);
currVal[1] = Compn.comparen(currVal[0][0], currVal[0][1], currVal[0][2], bit6, bit14);
currVal[2] = Compn.comparen(currVal[1][0], currVal[1][1], currVal[1][2], bit5, bit13);
currVal[3] = Compn.comparen(currVal[2][0], currVal[2][1], currVal[2][2], bit4, bit12);
currVal[4] = Compn.comparen(currVal[3][0], currVal[3][1], currVal[3][2], bit3, bit11);
currVal[5] = Compn.comparen(currVal[4][0], currVal[4][1], currVal[4][2], bit2, bit10);
currVal[6] = Compn.comparen(currVal[5][0], currVal[5][1], currVal[5][2], bit1, bit9);
currVal[7] = Compn.comparen(currVal[6][0], currVal[6][1], currVal[6][2], bit0, bit8);

comparatorOUT[0] = currVal[0][0] || currVal[1][0] || currVal[2][0] || currVal[3][0] || currVal[4][0] || currVal[5][0] || currVal[6][0] || currVal[7][0];
comparatorOUT[1] = currVal[0][1] || currVal[1][1] || currVal[2][1] || currVal[3][1] || currVal[4][1] || currVal[5][1] || currVal[6][1] || currVal[7][1];
comparatorOUT[2] = !comparatorOUT[0] && !comparatorOUT[1];

return comparatorOUT;
}

最佳答案

只有当方法是静态时才可以这样调用。

Compn.comparen

你应该这样做

Compn c = new Compn();
currVal[0] = c.comparen(false, false, true, bit7, bit15);

或与静态相比进行更改。

为什么不将 Compn 类放在方法之外呢?

关于java - 为什么这会导致错误 - Java 方法中的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20631373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com