I get a compile error "inconvertible types" for the following code at the line (B). Conceptually, I believe it should work. First, "adapter" is of type BasicAdapter, and BetaAdapter is a subclass of that. Second, the type parameter BetaData is a subclass of AlphaData.
public class Test
{
class AlphaData {} // base class for data
class BetaData extends AlphaData {} // subclass for data
class BasicAdapter<T> {} // a generic adapter
class BetaAdapter extends BasicAdapter<BetaData> {} // adapter subclass with binding
BasicAdapter<AlphaData> adapter = null; //(A)
Test()
{
BetaAdapter ba = (BetaAdapter) adapter; //(B)
}
}
If I change the line marked (A) to
BasicAdapter<BetaData> adapter = null;
it compiles. That makes sense. But I would like to figure out a way to make the original arrangement work.