Walt
Walt

Reputation: 1436

the blank final field may not have been initialized

PS: There are questions with similar topic but what I am asking is essentially different.

I understand the reason behind the error

the blank final field may not have been initialized

when I try to do something like

  final Object[] items;

But what concerns me is the JDK ArrayBlockingQueue implementation HERE. How is that same line (line #87) is getting used here with no errors ?

Upvotes: 1

Views: 7412

Answers (1)

Andy897
Andy897

Reputation: 7133

It is because the fields are initialized in the constructor

  public ArrayBlockingQueue(int capacity, boolean fair) {
        if (capacity <= 0)
            throw new IllegalArgumentException();
        this.items = new Object[capacity];
        lock = new ReentrantLock(fair);
        notEmpty = lock.newCondition();
        notFull =  lock.newCondition();
    }

Upvotes: 4

Related Questions