Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9218871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:57:58+00:00 2026-06-18T02:57:58+00:00

I have a ListView listing a custom object (let’s say MyObject ). I want

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:58:00+00:00Added an answer on June 18, 2026 at 2:58 am

    Well, I finally managed to find a solution.

    Just as @Medo42 said:

    Another option is to check for and cast to List as the instanceof
    error suggests. Then you can iterate over the elements in the list and
    check if they are actually all instances of MyObject, and copy them to
    a new List.

    Even though I did not went through the process of creating a whole new object in order to make this particular case to work “warning-less” this was the right direction to go.

    So I took @lokoko ‘s idea and use it in a new setItems() method, with an Object parameter instead of a List<MyObject> in order to make sure

    The result code is the following:

    public void setItems(List<MyObject> var){
        this.list = var;
    }
    
    public void setItems(Object var){
        List<MyObject> result = new ArrayList<MyObject>();
        if (var instanceof List){
            for(int i = 0; i < ((List<?>)var).size(); i++){
                Object item = ((List<?>) var).get(i);
                if(item instanceof MyObject){
                    result.add((MyObject) item);
                }
            }
        }
        setItems(result);
    }
    

    Thanks everyone for your help!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview utilizing a custom adapter, now I want it to show
I have a ListView with Horizontal WrapPanel as its ItemsPanelTemplate. I want to get
I have a ListView and I want to specify the selection (item) mode. In
i have an android application which has a listview for listing 14 items inside
I have ListVIew that is filled with hard-coded DataModel . Then I want to
I have listview and I want to have show new window when someone double
I have a listview. In my listview I have a dropdownbox which I want
I created a ListView with a custom layout for each view. I have several
i have a custom list view. in that i am listing out images of
I have sectioned custom ListView that contains RadioButton on each items. When a Dialog

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.