Mirandas, bridges, overpasses

public interface A {
void a();
}
public abstract class B implements A {
/* nothing here */
}
public class C extends B {
void a() { /* some code */ }
}
public class Main {
public static void main(String[] s) {
B b = new C();
b.a();
}
}
$ javap -cp . B
Compiled from "B.java"
public abstract class B implements A {
public B();
}
$ javap -cp . B
Compiled from "B.java"
public abstract class B implements A {
public B();
public abstract void a();
}
public class Sup<A> {
void m(A a) { /* some code */ }
}
public class Sub extends Sup<Integer> {
void m(Integer a) { /* other code */ }
}
public class Sup {
void m(Object a) { /* some code */ }
}
public class Sub extends Sup {
void m(Integer a) { /* other code */ }
}
Object a = Integer.valueOf(0);
Sub s = new Sub();
s.m(a);
public class Sub {
void m(Integer a) { /* other code */ }
void m(Object a) { m((Integer) a); } //the bridge method
}
public class Sup2 {
Object k() { /* some code */ }
}
public class Sub2 extends Sup2 {
Integer k() { /* other code */ }
}
public class Sub2 {
Integer k() { /* other code */ }
Object k() { //the bridge method
invokevirtual Sub2.k()Ljava/lang/Integer;
}
}
class A {
void b() { /* some code for b */ }
void c() { /* some code for c */ }
}
class B extends A {
void a() { /* some code for a */ }
@Override void b() { /* some different code for b */ }
}
class C extends A {
@Override void c() { /* some different code for c */ }
void d() { /* some code for d */ }
}
class Main {
public static void main(String[] s) {
A a = new /* either A or B or C, who knows */;
a.b(); //compiled to: invokevirtual A.b()V
}
}
abstract class A {
abstract void a();
void b() { /* some code for b */ }
void c() { /* some code for c */ }
}
...
interface I {
void a();
}
abstract class A implements I {
...
}
...
interface I {
default void a() { /* some default code for a */ }
}
class A implements I {
void b() { /* some code for b */ }
void c() { /* some code for c */ }
}
...
interface I1 {
default void a() { /* some default code for a */ }
}
interface I2 {
default void a() { /* some other default code for a */ }
}
class A implements I1, I2 {
void b() { /* some code for b */ }
void c() { /* some code for c */ }
}
...

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store