On Jan 23, 2007, at 7:39 AM, Karan Malhi wrote:

Ok,

I got stuck at one point here. To be clear i am giving an example below: Lets say we have an interface X in java 5 which has a method which returns a
type Y as shown below

public interface X {
  Y a();
}

The same interface in Java 6 is, but it adds a method  named b, which
returns a type Z which is only available in java 6

public interface X {
 Y a();
 Z b();

}

Now lets say I have an existing class named XImpl

public class XImpl implements X {
  public Y a(){ return new Y();}
}

If I compile the above XImpl with Java 5, it would work fine, however the
compiler will complain in Java 6.

Using dynamic proxies would work fine at runtime in both Java 5 and Java 6.
My question is , how do i satisfy the Java 6 compiler before i run the
program to generate the dynamic proxy?

Two thing pop to mind, the first is to simply always build on 5 but we would be able to run on 6, but that would defeat the purpose of this question :)

We could have our implementation class not implement the interface and dynamically add the interface later. To keep ourselves sane we could make our own copy of the interface. Using your example:

1.5
public interface X {
  Y a();
}

1.6
public interface X {
  Y a();
  Z b();
}

OpenEJB
public interface OurX {
  Y a();
}
public class OurXImpl {
  Y a() { return doSomething(); }
}

Dynamic proxy 1.5 {
public class Ximpl implements X {
  private final OurXImpl x;
  Y a() { return x.a(); }
}

Dynamic proxy 1.6 {
public class Ximpl implements X {
  private final OurXImpl x;
  Y a() { return x.a(); }
  Z b() { throw new UnsupportedOperationException(); }
}

This should work. Alternatively, we could, as David suggested, try to ship our own version of the missing javax.sql classes. I'm not sure what is easiest.

-dain

Reply via email to