Skip to content

Tag: java

Optional parameters: Multiple constructors cause errors

Since in Java optional parameters are not possible, I tried to create 2 constructors. Now my problems are the private properties. There I get the error Variable ‘_mediaPlayer’ might not have been initialized In another method, I want to check if the properties are set. But how can I avoid these er…

Segment class in ConcurrentHashMap usage

Looking into implementation of ConcurrentHashMap, I see that when trying to manipulate it(put/remove), value is found and this value is then used as lock for synchronized code which performs actual manipulation. This way only that bucket is locked where value actually exists. I also see a class Segment declar…

Parameter to pass in for type Class

I am trying to make a generic Stack class as shown but am unsure of what to put in for type when instantiating since I thought of doing however I get the following error of so I thought of using but I am unsure of what to put inside of cast() since it won’t take now I am stuck. Answer