You cannot do this at compile time in Java. I think that the best you can do is to try to verify this at runtime, by using reflection to do something like:
public static <T> boolean hasDefaultConstructor(Class<T> cls) {
Constructor[] constructors = cls.getConstructors();
for (Constructor constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
return true;
}
}
return false;
}
Then you can invoke this function by doing the following:
hasDefaultConstructor(String.class) => true;
hasDefaultConstructor(Integer.class) => false;
If this function returns false, then you know the class will have no default constructor, and you can throw an exception or whatever is appropriate for your application.