我瞭解到,要訪問靜態成員類,語法是OuterClass.NestedStaticClass
。下面訪問靜態成員類
對於以下接口Input
給定的,
interface Input{
static class KeyEvent{
public static final int KEY_DOWN = 0;
public static final int KEY_UP = 0;
public int type;
public int keyCode;
public int keyChar;
}
static class TouchEvent{
public static final int TOUCH_DOWN = 0;
public static final int TOUCH_UP =0;
public static final int TOUCH_DRAGGED = 2;
public int type;
public int x, y;
public int pointer;
}
public boolean isKeyPressed(int keyCode);
.....
public List<KeyEvent> getKeyEvents();
public List<TouchEvent> getTouchEvents();
}
是實現Keyboard
,
class Keyboard implements Input{
....
@Override
public List<TouchEvent> getTouchEvents() {
TouchEvent obj1 = new TouchEvent();
TouchEvent obj2 = new TouchEvent();
List<TouchEvent> list = new ArrayList<TouchEvent>();
list.add(obj1);
list.add(obj2);
return list;
}
}
在此實現Keyboard
,我並不需要使用Input.TouchEvent
低於行代碼。
TouchEvent obj1 = new TouchEvent();
TouchEvent obj2 = new TouchEvent();
List<TouchEvent> list = new ArrayList<TouchEvent>();
但下面執行,我不得不用Input.TouchEvent
,
public class NestedClassInInterface {
public static void main(String[] args) {
Input.TouchEvent t = new Input.TouchEvent();
}
}
如何理解?
因爲要實現在你前面的情況接口'input' .. – Babel
如果您實現接口'Input',如何訪問的範圍'KeyEvent'不同? – overexchange