916
技術社區[雲棲]
static class 和 static interface
今天看代碼,不斷看到static class 和 static interface,也不明白是什麼意思。經過多方搜索,總算讓我找到了答案。
先看下麵一個例子吧:
public class InnerClass1
{
static class A
{
void methodA()
{
System.out.println("sdfsdf");
}
}
public static void main(String[] args)
{
new InnerClass1().new A().methodA();
}
}
static class屬於內部類,相當於類的一個成員。隻能通過外部類來調用它。
同樣,static interface也是這樣,隻能在包含它的類中實現和使用。
最後更新:2017-04-03 12:55:10