Class Part4_InterfaceMonomorphism
java.lang.Object
Part4_InterfaceMonomorphism
Demonstrates monomorphic dispatch: because
PureBreedDog is
final, the JIT can devirtualize the call and invoke speak()
directly, without an itable/vtable lookup.
Disassembled bytecode (javap -c):
Compiled from "Part4_InterfaceMonomorphism.java"
public class Part4_InterfaceMonomorphism {
public Part4_InterfaceMonomorphism();Code:0:aload_0 1:invokespecial#1 // Method java/lang/Object."<init>":()V
4:return
public static void directSpeak(PureBreedDog);
Code:
0: aload_0
1: invokevirtual #7 // Method PureBreedDog.speak:()V
4: return
public static void main(java.lang.String[]);
Code:
0: new #8 // class PureBreedDog
3: dup
4: invokespecial #12 // Method PureBreedDog."<init>":()V
7: astore_1
8: aload_1
9: invokestatic #13 // Method directSpeak:(LPureBreedDog;)V
12: return
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddirectSpeak(PureBreedDog explicitDog) Scenario A: Monomorphic target explicitly declared by final type reference.static void
-
Constructor Details
-
Part4_InterfaceMonomorphism
public Part4_InterfaceMonomorphism()
-
-
Method Details
-
directSpeak
Scenario A: Monomorphic target explicitly declared by final type reference.- Parameters:
explicitDog- concrete, non-overridablePureBreedDogreference.
-
main
-