javatypes

Is the any way to create String Literal Types in Java?


I'm new to Java.

I've been using Typescript to type my projects in the Front-end and I'm very used to creating String Literal Types to limit possible inputs. Is there any easy way to this in Java?

For eye candy, here's how you create it in Typescript:

type Easing = "ease-in" | "ease-out" | "ease-in-out";

Solution

  • No. The most similar thing is an enum Type.

    public enum Easing {
        EASE_IN, EASE_OUT, EASE_IN_OUT;
    }