generics raw type

hi all!

I've made a small program and I didn't define A as a raw type so

I don't understand why this simple part of code is executed properly?

why method aka.add(new Integer(2)) works even if A is A<Boolean>

class A<E>{

int position;

Object field[];

public A(int size){

position=0;

field=new Object[size];

}

public <E>void add(E objekt){

field[position]=objekt;

position++;

}

void print(){

for(Object o: field)

System.out.println(">> " + o.toString()+" << ");

}

}

class generics{

publicstaticvoid main(String args[]){

A<Boolean> aka =new A<Boolean>(3);

aka.add(new Integer(2));

aka.add(new String("bok"));

aka.add(new Boolean(true));

aka.print();

}

}

[1874 byte] By [EqAfricaa] at [2007-10-3 2:51:59]
# 1

If you just hadpublic void add(E objekt)

then your code would fail to compile, as you expect. But you used a type parameter on the method that hides the type parameter of the class, and then you failed to supply that parameter in the code that calls the method.

DrClapa at 2007-7-14 20:40:53 > top of Java-index,Core,Core APIs...
# 2
thank you Paul for your concise and clear answer, you have enlighten me...best regards
EqAfricaa at 2007-7-14 20:40:53 > top of Java-index,Core,Core APIs...