![](/img/trans.png)
[英]JSF: p:dataTable with f:attribute results in “argument type mismatch” error
[英]Why Type mismatch error is thrown up when F in “(F obj)” is replaced with Factory. What is F at compile time
為什么將“(F obj)”中的F替換為Factory時會引發類型不匹配錯誤。 在編譯時F是什么,是Object還是編譯時F。
interface Factory<T>
{
T create();
}
class FirstClass<T>
{
T x;
<F extends Factory<T>> FirstClass(F obj)// Error will be thrown when F in (F obj)
// is replaced with Factory. Error will be
// cannot convert from "Object to T"
{
x = obj.create();
}
}
class integerFactory implements Factory<Integer>
{
@Override
public Integer create() {
return 1000;
}
}
public class testGenerics {
public static void main(String[] args) {
new FirstClass<Integer>(new integerFactory());
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.