Suppose the situation in which we must have list of WeakReference and "Strong Reference".But there are not StrongReference class in Java.My solution is
Keep list of objects
List<? extends Object> list =new ArrayList();
and any time when we get element from list, check:
if(list.get(i) instanceof WeakReference){
MyClass myObject = ((MyClass)((WeakReference) list.get(i)).get());
if(myObject != null){
myObject.doSomething();
}
}else{
MyClass myObject = ((MyClass)list.get(i));
myObject.doSomething();
}
Is there better solution to keep strong and weak references together in one collection?.