Java Inner Class, Static Inner Class, Inner Interface
class A{
public static class B{
}
public class C{
}
public interface IF{
}
public IF create(){
/**
* local inner class
*/
class F implements IF{
}
return new F();
}
/**
* 和C#类似,好熟悉的匿名委托阿
* @return
*/
public IF createAnother(){
return new IF(){
};
}
}
class X implements A.IF{
}
interface IShare{
class A{
}
A getData();
}
public class ClientConsole{
public static void main(String[] args){
A.B b = new A.B();
System.out.println(b.getClass().getName());
A.C c = (new A()).new C();
System.out.println(c.getClass().getName());
A.IF x = new X();
System.out.println(x.getClass().getName());
System.out.println(x instanceof A.IF);
A.IF f1 = (new A()).create();
// local inner class 仅仅显示为外部可见类型
System.out.println(f1.getClass().getName());
System.out.println(f1 instanceof A.IF);
A.IF f2 = (new A()).create();
System.out.println(f2.getClass().getName());
System.out.println(f2 instanceof A.IF);
System.out.println(IShare.A.class.getName());
}
}
public static class B{
}
public class C{
}
public interface IF{
}
public IF create(){
/**
* local inner class
*/
class F implements IF{
}
return new F();
}
/**
* 和C#类似,好熟悉的匿名委托阿
* @return
*/
public IF createAnother(){
return new IF(){
};
}
}
class X implements A.IF{
}
interface IShare{
class A{
}
A getData();
}
public class ClientConsole{
public static void main(String[] args){
A.B b = new A.B();
System.out.println(b.getClass().getName());
A.C c = (new A()).new C();
System.out.println(c.getClass().getName());
A.IF x = new X();
System.out.println(x.getClass().getName());
System.out.println(x instanceof A.IF);
A.IF f1 = (new A()).create();
// local inner class 仅仅显示为外部可见类型
System.out.println(f1.getClass().getName());
System.out.println(f1 instanceof A.IF);
A.IF f2 = (new A()).create();
System.out.println(f2.getClass().getName());
System.out.println(f2 instanceof A.IF);
System.out.println(IShare.A.class.getName());
}
}
输出:
A$B
A$C
X
true
A$1F
true
A$1F
true
IShare$A
贸易电子化,技术全球化