Skip to content

Instantly share code, notes, and snippets.

@hengyunabc
Last active November 30, 2015 02:13
Show Gist options
  • Save hengyunabc/c906aa26c213cc74c5dc to your computer and use it in GitHub Desktop.
Save hengyunabc/c906aa26c213cc74c5dc to your computer and use it in GitHub Desktop.
可以在匿名类里用{}来进行一些初始化工作,这样子可以避免要写一个构造函数。
scheduleJobManager.addScheduleJob(new ScheduleJobSupport(){
{
this.setInterval(intervalx);
}
@Override
public boolean permitAdd() {
return false;
}
});
@hengyunabc
Copy link
Author

同样的技巧可以用来初始化一个Map。

        Map<String, String> map = new HashMap<String, String>(){
            {
                this.put("abc", "xyz");
            }
        };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment