0

There are two classes. One, X , has it's own blockingQueue and also method returning it:

public int getQueue(){
    return TaskQueue;
}

but it seems it returns queue's reference. And I need to operate on it in other class Y where there is x.getQueue().take(); . So is there any way to pass queue with getters / setters ?

prgst
  • 121
  • 1
  • 1
  • 11

1 Answers1

1
public int getQueue()
{
    return TaskQueue;
}

You are trying to returning the TaskQueue class as an int and not your TaskQueue object.

I don't know how's your code structure, but here is an example of what you want to do:

class X
{
    private BlockingQueue taskQueue;

    public X()
    {
        taskQueue = new BlockingQueue();
    }

    public BlockingQueue getQueue()
    {
        return taskQueue;
    }
}

And you can use this in any other class:

X myXClassObject = new X();

myXClassObject.getQueue().blockingQueueMethod();

or in a more understandable way:

X myXClassObject = new X();

BlockingQueue myQueue = myXClassObject.getQueue();

myQueue.blockingQueueMethod();
myQueue.take();
  • Oh dear, terrible mistake I made here rewriting the method. In my program it is as a BlockingQueue not as an int. I am so sorry. Though, it is not working there – prgst Jun 04 '15 at 11:37
  • Then the problem must be located at the method's return value. Is TaskQueue a Class or an Object? – Rui Filipe Pedro Jun 04 '15 at 13:07
  • Object. But I found the mistake. I was missing `X myXClassObject = new X();` I must had been bait distracted. Thank You very much. :) – prgst Jun 04 '15 at 19:47