Tuesday, 13 August 2013

java generic method invocation 1

java generic method invocation 1

Why can't we use new Organic(), new Aliphatic() and new Hexane() as
arguments of method react() for line A? and Organic() for line B.
public class Organic < E> {
void react(E e) { }
static void main(String[] args)
{
//line A- Organic< ? extends Organic> compound = new Aliphatic< Organic>();
//line B- Organic< ? super Aliphatic> compound = new Aliphatic< Organic>();
compound.react(new Organic());
compound.react(new Aliphatic());
compound.react(new Hexane());
} }
class Aliphatic < F> extends Organic< F> { }
class Hexane< G> extends Aliphatic< G> { }

No comments:

Post a Comment