關與class和interface的幾個語法問題
阿新 • • 發佈:2019-02-17
1,非靜態內部類持有外部類引用,但是非靜態內部類的內部介面的實現類物件持有最外層類的引用麼?
Handler myHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case TestHandler.GUIUPDATEIDENTIFIER:
myBounceView.invalidate();
break ;
}
super.handleMessage(msg);
}
};
2,再說幾個語法
package com.example.autoinstall;
public class TestDemo317 {
// 內部接口裡面還可以寫介面
interface Intf0 {
public interface Intf0Sub0 {
void test();
}
}
// 非靜態內部類裡面不可以寫介面
class Class0 {
interface Class0InnerIntf {// The member interface Tof1 can only be
// defined inside a top-level class or
// interface
void test();
}
}
// 靜態內部類裡面可以寫介面
static class Class1 {
public interface InnerIntf1 {
void test();
}
}
// 內部接口裡面的介面中可以再巢狀一個介面
interface Intf2 {
public interface InnerIntf1 {
public interface InnerIntf2 {
void test();
}
void test();
}
}
interface Intf3 {
public interface InnerIntf1 {
public interface InnerIntf1 {// public interface不能和上級同名,The nested
// type InnerIntf1 cannot hide an
// enclosing type
void test();
}
void test();
}
}
interface Intf4 {
public interface InnerIntf1 {
interface InnerIntf1 {// interface不能和上級同名,The nested type InnerIntf1
// cannot hide an enclosing type
void test();
}
void test();
}
}
// 非靜態內部類裡面還可以寫非靜態內部類
class Class3 {
class Class4 {
}
}
class Class4 {
class Class4 {// 不能和上級同名,The nested type Class4 cannot hide an enclosing
// type
}
}
// 靜態內部類裡面還可以寫非靜態內部類
static class Class5 {
class Class6 {
}
}
// 靜態內部類裡面還可以寫靜態內部類
static class Class6 {
static class Class7 {
}
}
// 非靜態內部類裡面不可以寫靜態內部類
class Class7 {
static class Class8 {// The member type Tof8 cannot be declared static;
// static types can only be declared in static
// or top level types
}
}
}