I’m trying to generate a ParameterizedType using Guice’s Types library. Butler is an inner class or inner interface. When I use the code like the following, I get the error “No owner type for enclosed interface”. Why?
private Butler<Person> findButler(Person person, Injector injector){
Class<? extends Person> personClass = person.getClass();
ParameterizedType parameterizedButler =
Types.newParameterizedType(Butler.class, personClass);
Key<?> key = Key.get(parameterizedButler);
Butler<Person> butler = (Butler<Person>) injector.getInstance(key);
return butler
}
Per Sam Berlin’s answer, the “No owner type for enclosed interface” error means that if [in this case] Butler is an inner class, you’ll need to use the three-argument
newParameterizedTypeWithOwner method and pass the outer class as the owner [first] argument.
So the correct code would look something like this: