android - creating generic interface for two List wrappers


I have to perform similar methods on two types of lists.

private List<WifiConfiguration> wifiConfigurations;
private List<ScanResult> mScanResults;

I need to scan both lists and look for some specific item, so I figured I'll create an interface to wrap them up, and then implement each doesListContains method.

public interface IWifiListWrapper {
    boolean doesListContains(IWifiInfo wifiInfo);
    //  <T> void setList(List<T> wifiList);

And one implementation for example is:

public class ScanResultsListWrapper implements IWifiListWrapper {

    private List<ScanResult> mScanResults;

    public boolean doesListContains(IWifiInfo wifiInfo) {

That's all good.

Now, I also need to have a setList method to set the list in each of the implementations to their specific List types (WifiConfiguration and ScanResult).

It looks like is should be implemented with Generics somehow, but I am not really sure How do I do it.. I do need to somehow declare each list in the beginning with its Type, correct? so I can pass a matching List type.

How should I go about it?

public interface IWifiListWrapper

This video can help you solving your question :)
By: admin