Reading Maps of strings and doubles from CSV I want to have 2 classes responsible for reading dictionaries from CSV.
The 1st class takes 2 columns from CSV and makes Map&lt;String, String&gt;.
The 2nd class takes 2 columns from CSV and makes Map&lt;String, Double&gt;.  

I want to solve it according to DRY rule so I've made a generic method for making Map&lt;T1, T2&gt; from csv which will be used by 1st class and 2nd class. It goes like this: 

package Main;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.function.Function;

public interface MapFromCsv&lt;T1, T2&gt; {

    public default Map&lt;T1, T2&gt; getMap(String FILE_TO_LOAD, Function&lt;String, T1&gt; foo1, Function&lt;String, T2&gt; foo2){
        Map&lt;T1, T2&gt; mapResult = new HashMap&lt;&gt;();
        File f = new File(FILE_TO_LOAD);
        try (Scanner sc = new Scanner(f)) {
            while (sc.hasNextLine()) {
                String tmp = sc.nextLine();
                String[] tmp2 = tmp.split(";");
                mapResult.put((T1) foo1.apply(tmp2[0]), (T2) foo2.apply(tmp2[1]));
            }
        } catch (FileNotFoundException fntf) {
            System.err.println("File " + f.getPath() + "was not found.");
        } catch (Exception e) {
            System.err.println("Something went wrong with reading " + f.getPath());
        }
        return mapResult;
    }
}


and implementation of the first class for making Map&lt;String, String&gt; goes like this: 

package Main;

import java.util.Map;

public enum StringMapFromCsv implements MapFromCsv&lt;String, String&gt; {

    INSTANCE;
    final String FILE_TO_LOAD = "resources/stringMap.csv";
    private Map&lt;String, String&gt; stringMap;

    private StringMapFromCsv() {
        initStringMap();
    }

    private void initStringMap() {
        this.stringMap = getMap(FILE_TO_LOAD);
    }

    public void reloadStringMap() {
        initStringMap();
    }

    public Map&lt;String, String&gt; getStringMap() {
        return stringMap;
    }

}


and implementation of the second class for making Map&lt;String, Double&gt; goes like this: 

package Main;

import java.util.Map;

public enum DoubleMapFromCsv implements MapFromCsv&lt;String, Double&gt;{

    INSTANCE;
    final String FILE_TO_LOAD = "resources/doubleMap.csv";
    private Map&lt;String, Double&gt; doubleMap;

    private DoubleMapFromCsv() {
        initDoubleMap();
    }

    private void initDoubleMap() {
        this.doubleMap = getMap(FILE_TO_LOAD);
    }

    public void reloadDoubleMap() {
        initDoubleMap();
    }

    public Map&lt;String, Double&gt; getDoubleMap() {
        return doubleMap;
    }

}


Anu suggestions?
This really looks like you over-designed the solution. And especially tricky since it won't work right now. (You're calling an unknown method getMap(FILE_TO_LOAD), it's missing the 2 mapping functions as parameters).

Why not just create a factory class that creates maps from the CSV files?

public class MapFactory {
    private static final String STRING_FILE = "resources/stringMap.csv";
    private static final String DOUBLE_FILE = "resources/doubleMap.csv";

    //private constructor to prevent pointless instance creation of this class
    private MapFactory() {
    }

    private static Map&lt;String, String&gt; createStringMap() {
        return createMapFromFile(STRING_FILE, Function.identity());
    }

    private static Map&lt;String, Double&gt; createDoubleMap() {
        return createMapFromFile(DOUBLE_FILE, Double::parseDouble);
    }

    public static &lt;T&gt; Map&lt;String, T&gt; createMapFromFile(String inputFile, Function&lt;String, T&gt; parseFunction) {
        Map&lt;String, T&gt; mapResult = new HashMap&lt;&gt;();
        File f = new File(inputFile);
        try (Scanner sc = new Scanner(f)) {
            while (sc.hasNextLine()) {
                String line = sc.nextLine();
                String[] lineParts = line.split(";");
                mapResult.put(lineParts[0], parseFunction.apply(lineParts[1]));
            }
        } catch (FileNotFoundException fntf) {
            System.err.println("File " + f.getPath() + "was not found.");
        } catch (Exception e) {
            System.err.println("Something went wrong with reading " + f.getPath());
        }
        return mapResult;
    }
}


You should really change the names of "stringMap" and "doubleMap" to something more meaningful. I can't do that for you here since you did not provide the actual use of your code.

Notice how I just extracted the common part into it's own method here?

I did throw away the map field so you'll need to re-read the file on each new creation. This greatly depends on how you plan on using these maps. With this solution the different classes that use the maps are free to modify it without breaking any other classes that use the map.

Alternatively you can also save the map in a field and use (thread safe) lazy loading to only initialise the map once, the first time it's used like this:

public class MapFactory {
    private static final String STRING_FILE = "resources/stringMap.csv";
    private static final String DOUBLE_FILE = "resources/doubleMap.csv";

    //private constructor to prevent pointless instance creation of this class
    private MapFactory() {
    }

    private static class StringMapHolder {
        private static final Map&lt;String, String&gt; STRING_MAP =createMapFromFile(STRING_FILE, Function.identity()); 
    }

    public static Map&lt;String, String&gt; createStringMap() {
        return StringMapHolder.STRING_MAP;
    }
    private static class DoubleMapHolder {
        private static final Map&lt;String, Double&gt; DOUBLE_MAP = createMapFromFile(DOUBLE_FILE, Double::parseDouble);

    }

    public static Map&lt;String, Double&gt; createDoubleMap() {
        return DoubleMapHolder.DOUBLE_MAP;
    }

    private static &lt;T&gt; Map&lt;String, T&gt; createMapFromFile(String inputFile, Function&lt;String, T&gt; parseFunction) {
        Map&lt;String, T&gt; mapResult = new HashMap&lt;&gt;();
        File f = new File(inputFile);
        try (Scanner sc = new Scanner(f)) {
            while (sc.hasNextLine()) {
                String line = sc.nextLine();
                String[] lineParts = line.split(";");
                mapResult.put(lineParts[0], parseFunction.apply(lineParts[1]));
            }
        } catch (FileNotFoundException fntf) {
            System.err.println("File " + f.getPath() + "was not found.");
        } catch (Exception e) {
            System.err.println("Something went wrong with reading " + f.getPath());
        }
        return mapResult;
    }
}