mvvmfx/src/main/java/de/saxsys/mvvmfx/internal/viewloader/ViewLoaderReflectionUtils.java
public static Optional<Field> getViewModelField(Class<? extends View> viewType, Class<?> viewModelType) {
        List<Field> allViewModelFields = getViewModelFields(viewType);

        if (allViewModelFields.isEmpty()) {
            return Optional.empty();
        }

        if (allViewModelFields.size() > 1) {
            throw new RuntimeException("The View <" + viewType + "> may only define one viewModel but there were <"
                    + allViewModelFields.size() + "> viewModel fields with the @InjectViewModel annotation!");
        }

        Field field = allViewModelFields.get(0);

        if (!ViewModel.class.isAssignableFrom(field.getType())) {
            throw new RuntimeException("The View <" + viewType
                    + "> has a field annotated with @InjectViewModel but the type of the field doesn't implement the 'ViewModel' interface!");
        }

        if (!field.getType().isAssignableFrom(viewModelType)) {
            throw new RuntimeException("The View <" + viewType
                    + "> has a field annotated with @InjectViewModel but the type of the field doesn't match the generic ViewModel type of the View class. "
                    + "The declared generic type is <" + viewModelType + "> but the actual type of the field is <"
                    + field.getType() + ">.");
        }

        return Optional.of(field);
    }
public static Optional<Field> getViewModelField(Class<? extends View> viewType, Class<?> viewModelType) {
        List<Field> allViewModelFields = getViewModelFields(viewType);

        if (allViewModelFields.isEmpty()) {
            return Optional.empty();
        }

        if (allViewModelFields.size() > 1) {
            throw new RuntimeException("The View <" + viewType + "> may only define one viewModel but there were <"
                    + allViewModelFields.size() + "> viewModel fields with the @InjectViewModel annotation!");
        }

        Field field = allViewModelFields.get(0);

        if (!ViewModel.class.isAssignableFrom(field.getType())) {
            throw new RuntimeException("The View <" + viewType
                    + "> has a field annotated with @InjectViewModel but the type of the field doesn't implement the 'ViewModel' interface!");
        }

        if (!field.getType().isAssignableFrom(viewModelType)) {
            throw new RuntimeException("The View <" + viewType
                    + "> has a field annotated with @InjectViewModel but the type of the field doesn't match the generic ViewModel type of the View class. "
                    + "The declared generic type is <" + viewModelType + "> but the actual type of the field is <"
                    + field.getType() + ">.");
        }

        return Optional.of(field);
    }
Returns the {@link java.lang.reflect.Field} of the viewModel for a given
view type and viewModel type. If there is no annotated field for the
viewModel in the view the returned Optional will be empty.

@param viewType
the type of the view
@param viewModelType
the type of the viewModel
@return an Optional that contains the Field when the field exists.