作者godfat (godfat 真常)
看板java
标题Re: [情报] Java 即将加入 Closure
时间Thu Aug 24 15:03:23 2006
※ 引述《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