Last active
August 29, 2015 14:23
-
-
Save mkarg/0da7f7dce8d9025511bb to your computer and use it in GitHub Desktop.
proxy7test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.Duration; | |
import java.util.Optional; | |
import java.lang.reflect.*; | |
public class Jre7Test { | |
public static interface I7 { | |
public void say(String greeting); | |
} | |
public static interface I8 extends I7 { | |
public Optional<Duration> optional(java.time.Duration duration); | |
public void say(String greeting); | |
} | |
public static class MyClass7 implements I7 { | |
public void say(String greeting) { | |
System.out.println("J7 says: " + greeting); | |
} | |
} | |
public static class MyClass8 extends MyClass7 implements I8 { | |
public Optional<Duration> optional(java.time.Duration duration) { | |
return Optional.of(duration); | |
} | |
public void say(String greeting) { | |
System.out.println("J8 says: " + greeting); | |
} | |
} | |
public static void main(String[] args) { | |
InvocationHandler handler = new InvocationHandler() { | |
public Object invoke(Object proxy, Method method, Object[] args) { | |
try { | |
return method.invoke(new MyClass8(), args); | |
} catch (Exception e) { | |
return new RuntimeException(e); | |
} | |
} | |
}; | |
I7 proxy = (I7) Proxy.newProxyInstance(Jre7Test.class.getClassLoader(), new Class[] { I7.class } , handler); | |
proxy.say("Hello from proxy"); | |
proxy.getClass().getMethods(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"C:\Program Files\Java\jdk1.8.0_45\bin\javac.exe" -source 1.7 -target 1.7 Jre7Test.java | |
warning: [options] bootstrap class path not set in conjunction with -source 1.7 | |
1 warning | |
"C:\Program Files\Java\jre7\bin\java.exe" Jre7Test | |
J7 says: Hello from proxy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think we can stop the discussion at this point. As long as the use of Reflection API upon JDBC objects is a wanted feature, the idea of sharing one single implementation simply won't work, or it will get too complicated to make it work.
When I started this discussion, I only had the JDBC spec in mind as-is, without any use of Reflection API on the JDBC objects, as neither of our own use cases covers this (we de no use such tools).