我有一个我需要转换回int []的ArrayList。我一直在尝试使用从List接口继承的T [] toArray(T [] a)方法。我查了几个例子,看来我做得对。有人可以告诉我为什么我会收到此错误吗?
有问题的代码行
keyCodes = projectedKeyCodes.toArray(new Integer[0]);
在
public KeyBindingsAdapter(JComponent c, int delay, int... keyCodes)
{
boolean allKeysSelected;
ArrayList<Integer> projectedKeyCodes = new ArrayList<Integer>();
for(int k: keyCodes)
{
if(k==ALPHA_KEYS)for(int p = 65; p < 91; p++)projectedKeyCodes.add(new Integer(p));
else if(k==NUMERIC_KEYS)for(int p = 48; p < 58; p++)projectedKeyCodes.add(new Integer(p));
else if(k==DIRECTIONAL_KEYS)for(int p = 224; p < 228; p++)projectedKeyCodes.add(new Integer(p));
else if(k==NUMPAD_KEYS)for(int p = 96; p < 112; p++)projectedKeyCodes.add(new Integer(p));
else if(k==FUNCTION_KEYS)for(int p = 112; p < 124; p++)projectedKeyCodes.add(new Integer(p));
else if(k==ALL_KEYS)allKeysSelected = true;
}
if(allKeysSelected)
{
keyCodes = new int[]{10,8,9,3,12,16,17,18,19,20,27,32,33,34,35,36,37,38,39,40,44,45,46,47,48,49,50,51,52,53,54,55,56,57,59,61,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,96,97,98,99,100,101,102,103,104,105,106,107,108,108,109,110,111,127,144,145,112,113,114,115,116,117,118,119,120,121,122,123,154,155,156,157,192,222,224,225,226,227,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,150,151,152,153,160,161,162,512,513,514,515,516,517,518,519,520,521,522,523,524,525,24,28,29,30,31,21,25,240,241,242,243,244,245,256,257,258,259,260,261,262,263,0};
}
else
{
keyCodes = projectedKeyCodes.toArray(new Integer[0]);
}
...
...
}
错误
KeyBindingsAdapter.java:41: error: incompatible types: inference variable T has incompatible upper bounds int,Object
keyCodes = projectedKeyCodes.toArray(new Integer[0]);
^
where T is a type-variable:
T extends Object declared in method <T>toArray(T[])
想法?