作者godfat (godfat 真常)
看板java
标题Re: [情报] Java 即将加入 Closure
时间Fri Sep 1 05:19:32 2006
※ 引述《jtmh (Believing is seeing! ^^)》之铭言:
: 有喔,它是先引入 function types 与 local functions,
: 然後再把 local functions 简化为 anonymous functions (closures) 的,
: 以下是它的范例:
: public static void main(String[] args) {
: int plus2(int x) { return x+2; }
: int(int) plus2b = plus2;
: System.out.println(plus2b(2));
: }
这个不是 function pointer 的概念,没有说明如何包装物件方法
假设:
void print( int() f ){
System.out.println( f() );
}
下面这要怎麽做?
Integer i = new Integer(10);
print( i.hashCode );
还是会变成这样:
print( int(){ return i.hashCode(); } );
这就是多此一举了
不过我觉得 Java 的设计理念就是要你多打一点字
为了省几个字换来更复杂的东西,似乎一直是 Java 避免的
也许 closure 就已经是很大的让步了也说不定
--
Hear me exalted spirits. Hear me, be you gods or devils, ye who hold
dominion here:
I am a wizard without a home. I am a wonderer seeking refuge.
Sacrifice
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.135.28.18