JDK8新特性☞访问对象字段和静态变量测试

/**
 * JDK8新特性☞访问对象字段与静态变量:可读又可写
 * 
 * @author Administrator
 *
 * @param
 * @param
 */
@FunctionalInterface
public interface Convert {


T convert(F from);


class Object {
static int outerStaticNum;
int outerNum;


void test() {
Convert convert = (from) -> {
outerNum = 23;
return String.valueOf(from + outerNum);
};
String string = convert.convert(20);
System.out.println(string);
Convert convert2 = (from) -> {


outerStaticNum = 66;
return String.valueOf(from + outerStaticNum);
};
String convert3 = convert2.convert(50);
System.out.println(convert3);
}


}


public static void main(String[] args) {
Object object = new Object();
object.test();
}

}

测试结果:


你可能感兴趣的:(测试类)