There is a function get() that return a value if it is there in ArrayDeque otherwise returns null i.e x can be some value or null. If get() returns x then function B() should perform some computations otherwise should not do anything.
T get()
{
//compute x
return x;
}
void B()
{
int z;
if(y.get()!=null)
{
z=y.get(); // gives null pointer exception
.....
}
}
The problem is that y.get() already returns the value which is not assigned to any variable, thus gives null pointer exception. If i use something like if((z=y.get()) != 0) it gives exception in cases when x is null. How can i achieve this functionality?
getitself that throws. Are you sure you're looking at the right part of your code?get()returnT, or anInteger? B() seems to assume that it's an Integer.