Home > Net >  How to pass object of type Map<String,?> as argument to function
How to pass object of type Map<String,?> as argument to function

Time:05-04

I have an abstract base class that has the following private variable

private Map<String, ?> options;

I want every other class that will extend my base class to implement the following method

protected abstract void initOptions(Map<String,?> options)

my problem is that I can't choose any other type than Map for the implementation

@Override
protected void initOptions(Map options) throws InternalLoginException {
    ...
}

What is the proper way to handle such a situation where I do not have control over the type of the options Map but I want to let the implementing class of the initOptions method know that the key in the Map is of type String and the value could be any Object.

CodePudding user response:

public abstract class BaseClass {

    abstract void methodToOverRide(Map<String, ?> parameter);


    static class SubClass extends BaseClass{

        @Override void methodToOverRide(Map<String, ?> parameter) {

            //do something?
        }
    }
}

What you have should work as shown above.

  • Related