Need a better way to create subclass instances from a base class reference FeatureMap contains features, derived classes have some mandatory features that the map should have, say keys (the mandatory part) are added and all the features are fetched from somewhere. Since clients interact with FeatureMap, a featuremap needs to be returned and the type is part of the actual object. Is there a better way to create instead of createFeatureMapWithMandatoryValues

import lombok.NonNull;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public abstract class FeatureMap {
    private Map&lt;String, Object&gt; features;
    public FeatureMap() {
        features = new HashMap&lt;&gt;();
    }
    void addFeature(@NonNull String name, @NonNull Object value) {
        features.put(name, value);
    }

    abstract FeatureMap createFeatureMapWithMandatoryValues(Map&lt;String, Object&gt; values);
}

class FoodFeatureMap extends FeatureMap {
    public static final String foodType = "foodType";

    public FoodFeatureMap(@NonNull String foodTypeValue) {
        addFeature(foodType, foodTypeValue);
    }

    @Override
    FeatureMap createFeatureMapWithMandatoryValues(Map&lt;String, Object&gt; values) {
        return new FoodFeatureMap((String) values.get(foodType));
    }
}

class HumanFeatureMap extends FeatureMap {
    public static final String name = "name";
    public static final String origin = "origin";

    public HumanFeatureMap(@NonNull String nameValue, @NonNull String originValue) {
        addFeature(name, nameValue);
        addFeature(origin, originValue);
    }

    @Override
    FeatureMap createFeatureMapWithMandatoryValues(Map&lt;String, Object&gt; values) {
        return new HumanFeatureMap((String)values.get(name), (String) values.get(origin));
    }
}

class Main {
    public static void main(String[] args) {
        FeatureMap featureMap = new FoodFeatureMap("Chinese");
        Map&lt;String, Object&gt; map = Collections.singletonMap(FoodFeatureMap.foodType, "Chinese");
        //assume this map contains more features fetched from somewhere given the earlier map having keys
        featureMap.createFeatureMapWithMandatoryValues(map);
    }
}
There sure is. You created a redundant way to create a FeatureMap and that is why you are having so much trouble with it. Your createFeatureMapWithMandatoryValues is pretty much useless.
When you do something such as:

FeatureMap featureMap = new FoodFeatureMap("Chinese");


You already have everything that you would ever want. By looking at FoodFeatureMap ctor we can see that you already correctly add the values that are mandatory because you have to create an instance of FoodFeatureMap by calling it.

public FoodFeatureMap(@NonNull String foodTypeValue) {
    addFeature(foodType, foodTypeValue);//this already correctly adds the value to the map
}


And thus the resulting code becomes this.

public abstract class FeatureMap {
    private Map&lt;String, Object&gt; features;
    public FeatureMap() {
        features = new HashMap&lt;&gt;();
    }

    protected void addFeature(@NonNull String name, @NonNull Object value) {
        features.put(name, value);
    }
}

class FoodFeatureMap extends FeatureMap {
    private static final String foodType = "foodType";

    public FoodFeatureMap(@NonNull String foodTypeValue) {
        addFeature(foodType, foodTypeValue);
    }
}

class HumanFeatureMap extends FeatureMap {
    private static final String name = "name";
    private static final String origin = "origin";

    public HumanFeatureMap(@NonNull String nameValue, @NonNull String originValue) {
        addFeature(name, nameValue);
        addFeature(origin, originValue);
    }
}


class Main {
    public static void main(String[] args) {
        FeatureMap featureMap = new FoodFeatureMap("Chinese");
        //do something with FeatureMap
    }
}


Now what comes ahead maybe for example turn your FeatureMap into an Iterable so you can get all the values that are on it