You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.4 KiB

/*
* 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 void foo(int x);
}
class UniqueImpl implements MyInterface {
public void foo(int x) {
for (int i = 0; i < x; i++) {}
}
}
public void call_interface_method_linear(MyInterface c, int x) {
c.foo(x);
}
interface MyInterface2 {
public void foo(int x);
}
abstract class AbsImpl implements MyInterface2 {
public abstract void foo(int x);
}
class Impl1 extends AbsImpl {
@Override
public void foo(int x) {
for (int i = 0; i < x; i++) {}
}
}
class Impl2 extends AbsImpl {
@Override
public void foo(int x) {}
}
/* By heuristics, [Impl1.foo] is selected. It is hard to say good or bad. */
public void call_interface_method2_linear(MyInterface2 c, int x) {
c.foo(x);
}
interface MyInterface3 {
public int unknown();
}
interface MyInterface4 {
public void top_cost(MyInterface3 x);
}
class UniqueImpl4 implements MyInterface4 {
public void top_cost(MyInterface3 i3) {
for (int i = 0; i < i3.unknown(); i++) {}
}
}
public void ignore_top_costed_sub_method_constant(MyInterface3 i3, MyInterface4 i4) {
i4.top_cost(i3);
}
}