これはオラクルページのチュートリアルの一部です:
次の例を検討してください。
List l = new ArrayList<Number>();
List<String> ls = l; // unchecked warning
l.add(0, new Integer(42)); // another unchecked warning
String s = ls.get(0); // ClassCastException is thrown
List<Number>
詳細には、静的タイプがである List オブジェクト l が、別の静的タイプを持つ別の List オブジェクト ls に割り当てられると、ヒープ汚染状況が発生します。 List<String>
// これは oracle チュートリアルからのものです。
私の質問は、なぜ静的型List<Number>
であり、単なる??ではないのですList
か?? 後で別の質問は私の研究のコードからのものです:
public class GrafoD extends Grafo {
protected int numV, numA;
protected ListaConPI<Adyacente> elArray[];
*/** Construye un Grafo con un numero de vertices dado*
* @param numVertices: numero de Vertices del Grafo
*/
@SuppressWarnings("unchecked")
public GrafoD(int numVertices){
numV = numVertices; numA=0;
elArray = new ListaConPI[numVertices+1];
for (int i=1; i<=numV; i++) elArray= new LEGListaConPI<Adyacente>();
}
ではなく、なぜこのコードでelArray = new ListaConPI[numVertices+1]
書くのelArray = new ListaConPI<Adyacente>[numVertices+1]
でしょうか?
どうもありがとう !