나는 다음과 같은 공장변환 공장 패턴
public class AppleFactory<T extends Fruit>
extends AbstractAppleFactory<Class<T>, TypeOfFruits, Fruits<T>>
{
private static final AppleFactory factroy = new AppleFactory();
private AppleFactory()
{
}
public static Fruits<? extends Fruit> get(Class<? extends Fruit> clazz,
TypeOfFruits typeOfFruits)
{
return (Fruits<? extends Fruit>) factroy.getInstance(clazz, typeOfFruits);
}
@Override
protected Fruits<T> newInstance(Class<T> clazz, TypeOfFruits typeOfFruits)
{
final Fruits<T> fruits;
fruits = new FruitsImpl<T>(clazz, typeOfFruits,"hello");
return fruits;
}
}
는 내가이 일을하여 Guice 모듈 후두둑로 변환 시도했다 :
@ImplementedBy(AppleFactoryImpl.class)
public interface AppleFactory<T extends Fruit>
{
Fruits<? extends Fruit> get(Class<? extends Fruit> clazz,
TypeOfFruits typeOfFruits)
}
@Singleton
public class AppleFactoryImpl implements AppleFactory
{
@Override
public Fruits<? extends Fruit> get(Class<? extends Fruit> clazz,
TypeOfFruits typeOfFruits)
{
final Fruits<T> fruits;
fruits = new FruitsImpl<T>(clazz, typeOfFruits,"hello");
return fruits;
}
}
을하지만 오류가 얻을 구현. 그것은 과일에 대한 유형 T를 해결할 수 없다고 말합니다.
내 최종 목표는 구체적인 구현에
FruitFactory 바인딩이 팩토리 즉 통해 다른 구현을 가지고 FruitFactory
입니다.
사람이이 문제를 해결하는 방법을 알고 있나요
이
는 공급자를 사용하도록 변경 될 수 있습니다 또는 다른 것, 나는 접근 방식에 너무 단단하지 않다?
최종 목표는 무엇입니까? 'FruitFactory''FruitFactory '을 구체적인 구현체에 바인딩 할 수 있습니까? –
@DavidRawson, 네, 그게 최종 목표입니다. 나는이 공장 안에 과일을 넣고 그것을 초기화 할 수 있는가? – Schumi
그게 좋습니다! 이것을 명확히하기 위해 질문을 편집 할 수 있습니까? 그러면 누군가가 대답 할 수있을 것입니다. –