if my method is accepting Queues from any type, how to determine if the method arg is ArrayBlockedQueue() or LinkedList() queue?
I used .equals as the following its always returning true
Queue q1 = new LinkedList();
Queue q2 = new ArrayBlockingQueue(4);
System.out.println(l1.equals(q1));
then I tried the following I have faced Illegal argument exception
public static void add2Q (Queue q) {
if(q.equals( new ArrayBlockingQueue(q.size()))){
q.offer(2);
q.offer(5);
q.offer(9);
q.offer(0);
q.offer(-1);
} else {
// thorws exception with add if exceeded
try {
q.add(2);
q.add(5);
q.add(4);
q.add(9);
q.add(10);
} catch (IllegalStateException e){
System.out.println("you are using ArrayBlockQueue of size "+ q.size() );
//e.printStackTrace();
}
}
}
Queueobject instead of a specific type.