I am creating a subclass of ListView which needs a specialized adapter that subclasses ListAdapter (CustomAdapter). I want to retain the setAdapter and getAdapter methods as they are standard methods which programmers expect to use with an AdapterView.
I can override the getter:
@Override
public CustomAdapter getAdapter() {...}
as it still returns a ListAdapter. However, I cannot override the setter:
@Override
public void setAdapter(CustomAdapter adapter) {...}
I get why Java won’t let me do this. So to get around it, right now, I do this:
@Override
public void setAdapter(ListAdapter adapter) {
throw new UnsupportedOperationException("adapter must be an instance of CustomAdapter");
}
public void setAdapter(CustomAdapter adapter) {
this.adapter = adapter;
}
I don’t think this is a big deal, but it sort of bugs me. It seems inelegant to still expose the original ListAdapter setter (esp. since it shows up in autocomplete lists). Is there any way to suppress the original setter, or is the above block the correct way to do this?
Thanks,
why not