所以我想知道爲什麼這會返回錯誤:「無法對Compn類型的非靜態方法comparen(args)進行靜態引用。我顯然不能使comparen()靜態方法,所以不知道有什麼問題。爲什麼這會導致錯誤 - 方法Java中的類
//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;
}
爲什麼你不能使'boolean [] compare' * static *? – Maroun