Re: [情報] Java 即將加入 Closure
※ 引述《Schelfaniel (Test)》之銘言:
: http://blogs.sun.com/roller/resources/ahe/closures.pdf
: 暫時先不評論, 不過這個算是其他很多語言都有的就是了...
終於不需要愚蠢的 interface 了嗎?真是可喜可賀…
不過總有種,Java 越來越不 Java 的感覺 -_-b
節錄:
public interface Runnable {
void run();
}
public interface API {
void doRun(Runnable runnable);
}
public class Client {
void doit(API api) {
api.doRun(new Runnable(){
public void run() {
snippetOfCode();
}
});
}
}
我一直覺得這種做法真的是非常地愚蠢,
如果我沒記錯的話,這還會導致產生一堆莫名其妙的 .class 檔
用一個生一次,用一堆的話就等著被 .class 淹死…
public interface API {
void doRun(void() func);
}
public class Client {
void doit(API api) {
api.doRun(() {snippetOfCode(); });
}
}
這個看起來真的清爽太多了…
雖然我覺得有些地方好像不應該省略
() { snippetOfCode(); }
改成
void() { snippetOfCode(); }
看起來比較不會那麼神秘
--
By Gamers, For Gamers - from the past Interplay
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.135.28.18
討論串 (同標題文章)