Java 方法的作用域中的内部类(不是在“外部类”的作用域中,当然,此处也没有相对的外部类)

版权声明:本文为博主原创文章,转载请注明原博客地址。 https://blog.csdn.net/u012210441/article/details/51926631

interface Contents{
	int value();
}

interface Destination{
	String readLabel();
}


public class Parcel3 {
	public Destination dest(String s){
		class PDestination implements Destination{
			private String label;
			private PDestination(String whereTo){
				label = whereTo;
			}
			public String readLabel(){
				return label;
			}
		}
		return new PDestination(s);
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Parcel3 p = new Parcel3();
		Destination d = p.dest("lalala");
		System.out.println(d.readLabel());
	}
}

上例中PDestination类即是方法dest中的内部类。

猜你喜欢

转载自blog.csdn.net/u012210441/article/details/51926631