Apr. 10th, 2005

juan_gandhi: (Default)
Sitting late on Sunday, writing stupid programs... what do you think this program would print?

    public static void main(String[] args) {
        List l0 = new Vector();
        List[] lists = new List[] {
                       l0,
                       new ArrayList(), 
                       new LinkedList(),
                       Arrays.asList(new Object[0]),
                       Collections.EMPTY_LIST,
                       Collections.nCopies(0, l0),
                       Collections.synchronizedList(l0),
                       Collections.synchronizedList(new Vector())};

        for (List l1 : lists) {
            for (List l2 : lists) {
                if (l1 != l2 && !l1.equals(l2)) {
                    System.out.println("oops, " + l1 +
                                       " is not the same as " + l2 +
                                       "!");
                }
            }
        }
    }

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
171819 20212223
2425 2627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 27th, 2025 04:21 am
Powered by Dreamwidth Studios