Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Test {
- public static void main(String[] args) {
- new Test();
- }
- ArrayList<Button> list = new ArrayList<Button>();
- int i;
- Test() {
- for (i = 0; i < 10; i++) {
- Button b = new Button(i);
- b.l = new Listener() {
- @Override
- public void trigger() {
- System.out.println(i + "");
- }
- };
- list.add(b);
- }
- for (Button b : list) {
- b.l.trigger();
- }
- }
- class Button {
- int i;
- Listener l;
- Button(int i) {
- this.i = i;
- }
- public void setListener(Listener l) {
- this.l = l;
- }
- }
- interface Listener {
- public void trigger();
- }
- }
Add Comment
Please, Sign In to add comment