PLEASE HELP!!
Im begging you people!
publicfinalclass Bundle<Eextends BundleElement, Fextends ID>implements IBundle<E, F>
publicboolean doesElementExist(F pID)
{
return (lookupIndex(pID) != (-1));
}
publicboolean doesElementExist(E pItem)
{
return doesElementExist(pItem.getID());
}
ID class:
import java.io.Serializable;
publicinterface IDextends Serializable
{
public String asText();
publicboolean doesMatch(ID pID);
}
The compiler flags the line
'return doesElementExist(pItem.getID());
as an error after inserting generics; is there any way to tell it that type parameter F is always an ID; and pItem.getID() always returns an ID; so why does it refuse to take the ID and store it in F?
[1605 byte] By [
alanpza] at [2007-10-2 5:30:01]

> The compiler flags the line
>
> 'return doesElementExist(pItem.getID());
>
> as an error after inserting generics; is there any
> way to tell it that type parameter F is always an ID;
> and pItem.getID() always returns an ID; so why does
> it refuse to take the ID and store it in F?
Type Parameter E is erased to BundleElement, thus pItem.getID() returns an ID. Why should this match public boolean doesElementExist(F pID) where F is an arbitrary subclass of ID?
You could solve this by generifying BundleElement as shown below.public final class Bundle<E extends BundleElement><F>, F extends ID> implements IBundle<E, F>
public boolean doesElementExist(F pID)
{
return (lookupIndex(pID) != (-1));
}
public boolean doesElementExist(E pItem)
{
return doesElementExist(pItem.getID());
}
interface BundleElement<F extends ID> {
public F getID();
}