View Javadoc
1   package gcUnrelatedTypes;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.HashSet;
6   import java.util.Iterator;
7   import java.util.LinkedList;
8   import java.util.List;
9   import java.util.ListIterator;
10  import java.util.Set;
11  
12  public class AllListsCouldBeEqual {
13  	
14  	static class MyList<E> implements List<E> {
15  
16  		public boolean add(E o) {
17  	        // TODO Auto-generated method stub
18  	        return false;
19          }
20  
21  		public void add(int index, E element) {
22  	        // TODO Auto-generated method stub
23  	        
24          }
25  
26  		public boolean addAll(Collection<? extends E> c) {
27  	        // TODO Auto-generated method stub
28  	        return false;
29          }
30  
31  		public boolean addAll(int index, Collection<? extends E> c) {
32  	        // TODO Auto-generated method stub
33  	        return false;
34          }
35  
36  		public void clear() {
37  	        // TODO Auto-generated method stub
38  	        
39          }
40  
41  		public boolean contains(Object o) {
42  	        // TODO Auto-generated method stub
43  	        return false;
44          }
45  
46  		public boolean containsAll(Collection<?> c) {
47  	        // TODO Auto-generated method stub
48  	        return false;
49          }
50  
51  		public E get(int index) {
52  	        // TODO Auto-generated method stub
53  	        return null;
54          }
55  
56  		public int indexOf(Object o) {
57  	        // TODO Auto-generated method stub
58  	        return 0;
59          }
60  
61  		public boolean isEmpty() {
62  	        // TODO Auto-generated method stub
63  	        return false;
64          }
65  
66  		public Iterator<E> iterator() {
67  	        // TODO Auto-generated method stub
68  	        return null;
69          }
70  
71  		public int lastIndexOf(Object o) {
72  	        // TODO Auto-generated method stub
73  	        return 0;
74          }
75  
76  		public ListIterator<E> listIterator() {
77  	        // TODO Auto-generated method stub
78  	        return null;
79          }
80  
81  		public ListIterator<E> listIterator(int index) {
82  	        // TODO Auto-generated method stub
83  	        return null;
84          }
85  
86  		public boolean remove(Object o) {
87  	        // TODO Auto-generated method stub
88  	        return false;
89          }
90  
91  		public E remove(int index) {
92  	        // TODO Auto-generated method stub
93  	        return null;
94          }
95  
96  		public boolean removeAll(Collection<?> c) {
97  	        // TODO Auto-generated method stub
98  	        return false;
99          }
100 
101 		public boolean retainAll(Collection<?> c) {
102 	        // TODO Auto-generated method stub
103 	        return false;
104         }
105 
106 		public E set(int index, E element) {
107 	        // TODO Auto-generated method stub
108 	        return null;
109         }
110 
111 		public int size() {
112 	        // TODO Auto-generated method stub
113 	        return 0;
114         }
115 
116 		public List<E> subList(int fromIndex, int toIndex) {
117 	        // TODO Auto-generated method stub
118 	        return null;
119         }
120 
121 		public Object[] toArray() {
122 	        // TODO Auto-generated method stub
123 	        return null;
124         }
125 
126 		public <T> T[] toArray(T[] a) {
127 	        // TODO Auto-generated method stub
128 	        return null;
129         }}
130 	public static void main(String arg[]) {
131 		falsePositive();
132 		
133 		List<Integer> lst = new LinkedList<Integer>();
134 		List<Integer> lst2 = (ArrayList<Integer>)lst;
135 		
136 		
137 		List<ArrayList<String>> mlist = null;
138 		mlist.contains(new LinkedList<String>());
139 
140 	}
141 	public static void falsePositive() {
142 		ArrayList<Integer> aLst = new ArrayList<Integer>();
143 		LinkedList<Integer> lLst = new LinkedList<Integer>();
144 		MyList<Integer> mLst = new MyList<Integer>();
145 		
146 		Set<ArrayList<Integer>> alSet = new HashSet<ArrayList<Integer>>();
147 		Set<LinkedList<Integer>> llSet = new HashSet<LinkedList<Integer>>();
148 		
149 		System.out.println(aLst.equals(lLst));
150 		System.out.println(mLst.equals(lLst));
151 		
152 		alSet.contains(lLst);
153 		alSet.contains(mLst);
154 		alSet.containsAll(llSet);
155 
156 	}
157 }