I have a ListView listing a custom object (let's say MyObject
).
I want to filter it dynamically through an EditText
so I had to implement a getFilter()
with a publishResults method:
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
MyObjectAdapter.this.setItems((List<MyObject>) results.values);
MyObjectAdapter.this.notifyDataSetChanged();
}
At this point, Eclipse complains: Type safety: Unchecked cast from Object to List<MyObject>
I am sure this cast will always be true, but Eclipse only suggests to add @SuppressWarnings("unchecked")
but I'm totally against SuppressWarnings
because it's only hiding the problem, not a solution...
I tried adding:
if(results.values instanceof List<MyObject>)
But Eclipse complains again, and this solves nothing...
Cannot perform instanceof check against parameterized type List<MyObject>. Use the form List<?>
I know the casting will always be correct, but which is the proper way to make the code to be sure results.values
is actually a List<MyObject>
?
Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…