Any way to force classes to have public static final field in Java?
class, inheritance, java
Solution
No, you can't.
You can only force them to have a non-static getter method, which would return the appropriate value for each subclass:
public abstract String getType();
If you need to map each subclass of something to a value, without the need to instantiate it, you can create a `public static Map<Class<?>, String> types;` somewhere, populate it statically with all the classes and their types, and obtain the type by calling `TypesHolder.types.get(SomeClass.class)`
Problem
Is there a way to force classes in Java to have public static final field (through interface or abstract class)? Or at least just a public field? I need to make sure somehow that a group of classes have `public static final String TYPE = "...";` in them.