Skip to content

Instantly share code, notes, and snippets.

@raphw
Last active August 29, 2015 14:26
Show Gist options
  • Save raphw/2155fa0f6ce222aed562 to your computer and use it in GitHub Desktop.
Save raphw/2155fa0f6ce222aed562 to your computer and use it in GitHub Desktop.
Visibility bridges
package pkg;
class GenericVisibilityBridge extends GenericVisibilityBridgeBase<Void> {
@Override
public void foo(Void aVoid) {
System.out.println("specialized");
}
}
package pkg;
public class GenericVisibilityBridgeBase<T> {
public void foo(T t) {
System.out.println("generalized");
}
}
package pkg;
public class GenericVisibilityBridgeTarget extends GenericVisibilityBridge {
/* empty */
}
import pkg.GenericVisibilityBridgeTarget;
public class VisibilityBridgeError {
public static void main(String[] args) throws Exception {
GenericVisibilityBridgeTarget.class.getMethod("foo", Object.class)
.invoke(new GenericVisibilityBridgeTarget(), new Object[]{null});
}
}
public class VisibilityBridges {
public static class Foo {
public void foo() {
/* empty */
}
}
static class Bar extends Foo {
public void bar() {
/* empty */
}
}
public static class Qux extends Bar {
/* empty */
}
public static void main(String[] args) throws Exception {
System.out.println(Qux.class.getMethod("foo"));
System.out.println(Qux.class.getMethod("bar"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment