Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Container implements Iterable<Integer> {
- private final List<Integer> list = new ArrayList<>();
- public void add(int i)
- { list.add(i); }
- public int length()
- { return list.size(); }
- public boolean isEmpty()
- { return list.isEmpty(); }
- @Override public Iterator<Integer> iterator()
- { return list.iterator(); }
- //////////////////////////////////////////////
- public static void main(String... args) {
- Container c;
- //Everytime we want to make sure c contains an instance of Container
- //We are forced to check against null
- if (c != null) c = new Container();
- //Even if we want to represent null as empty
- boolean empty = c == null || c.isEmpty();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment