How do I create some variable type alias in Java

There are no aliases in Java. You can extend the HashMap class with your class like this:

public class TheNewType extends HashMap<String, String> {
    // default constructor
    public TheNewType() {
        super();
    }
    // you need to implement the other constructors if you need
}

But keep in mind that this will be a class it won’t be the same as you type HashMap<String, String>

Leave a Comment