Re: [情報] Java 即將加入 Closure
※ 引述《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
討論串 (同標題文章)
完整討論串 (本文為第 10 之 16 篇):