Add example of lazy dynamic dispatch calling a method from the interface

Summary: Example of dynamic dispatch with interfaces were already working. Adding some tests now so that we don't break this.

Reviewed By: sblackshear

Differential Revision: D3220360

fb-gh-sync-id: 11395dd
fbshipit-source-id: 11395dd
master
Jeremy Dubreil 9 years ago committed by Facebook Github Bot 0
parent 2989105318
commit 3a856aa6f0

@ -9,7 +9,11 @@
package codetoanalyze.java.tracing; package codetoanalyze.java.tracing;
class A { interface I {
T get();
}
class A implements I {
public T get() { public T get() {
return new T(); return new T();
@ -17,7 +21,7 @@ class A {
} }
class B extends A { class B extends A {
public T get() { public T get() {
return null; return null;
@ -27,13 +31,27 @@ class B extends A {
public class LazyDynamicDispatchExample { public class LazyDynamicDispatchExample {
static T foo(A a) { static T fromSupertype(A a) {
return a.get(); return a.get();
} }
static void bar() { static T fromInterface(I i) {
return i.get();
}
static void callWithSubtype() {
B b = new B();
fromSupertype(b).f();
}
static void shouldNotReportLocalVarTypeIsKnown() {
A a = new A();
fromInterface(a).f();
}
static void shouldReportLocalVarTypeIsKnown() {
B b = new B(); B b = new B();
foo(b).f(); fromInterface(b).f();
} }
} }

@ -42,7 +42,8 @@ public class LazyDynamicDispatchTest {
public void matchErrors() public void matchErrors()
throws IOException, InterruptedException, InferException { throws IOException, InterruptedException, InferException {
String[] methods = { String[] methods = {
"bar" "callWithSubtype",
"shouldReportLocalVarTypeIsKnown",
}; };
assertThat( assertThat(
"Results should contain " + NPE, "Results should contain " + NPE,

Loading…
Cancel
Save