Summary: The heuristics is to find a method in non-abstract sub-classes. See D20647101. Reviewed By: jvillard Differential Revision: D20491461 fbshipit-source-id: 759713ef4master
parent
f0f91b21c6
commit
2eae5ff88c
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class InheritanceTest {
|
||||||
|
interface MyInterface {
|
||||||
|
public int foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
class UniqueImpl implements MyInterface {
|
||||||
|
public int foo() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void call_interface_method_Good(MyInterface x) {
|
||||||
|
int a[] = new int[10];
|
||||||
|
a[x.foo()] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void call_interface_method_Bad(MyInterface x) {
|
||||||
|
int a[] = new int[5];
|
||||||
|
a[x.foo()] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MyInterface2 {
|
||||||
|
public int foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class AbsImpl implements MyInterface2 {
|
||||||
|
public abstract int foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
class Impl1 extends AbsImpl {
|
||||||
|
@Override
|
||||||
|
public int foo() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Impl2 extends AbsImpl {
|
||||||
|
@Override
|
||||||
|
public int foo() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* By heuristics, [Impl1.foo] is selected. It is hard to say good or bad. */
|
||||||
|
public void call_interface_method2(MyInterface2 x) {
|
||||||
|
int a[] = new int[10];
|
||||||
|
a[x.foo()] = 0;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue