我想創建一個工廠(從一個String參數生成新的實例)。爲什麼使用番石榴創建工廠時會出現類型不匹配錯誤?
我有一個怪物類(超類)和Robot1類(擴展怪物)。
我廠聲明:
private static final ImmutableMap<String, Class<? extends Monster>> DISPATCHER = ImmutableMap.of("robot1", Robot1.class);
,但我得到:
Type mismatch: cannot convert from ImmutableMap<String,Class<Robot1>> to ImmutableMap<String,Class<? extends Monster>>
你爲什麼要加一箇中間投? –
@RohitJain中間劇組需要清除泛型以標記它可以接受任何事物,然後轉換爲具體的。 –
好的。是的,這是需要的。剛剛在'Number'和'Integer'上測試過。這是我不知道的。 +1 :) –