method refs: ambiguity checks into resolver; testdata

This commit is contained in:
anna
2012-09-27 17:59:03 +02:00
parent 67d6396df2
commit bcebb55f60
8 changed files with 180 additions and 49 deletions

View File

@@ -154,3 +154,32 @@ class MyTest5 {
}
}
public class MyTest6 {
interface I {
void _(Integer i);
}
static void foo(Number i) {}
static void foo(Integer i, String s) {}
static void foo(Integer d) {}
public static void main(String[] args) {
I s = MyTest6::foo;
s._(1);
}
}
public class MyTest7 {
interface I {
void _(Number i);
}
static void foo(Number i) {}
static void foo(Integer i, String s) {}
static void foo(Integer d) {}
public static void main(String[] args) {
I s = MyTest7::foo;
s._(1);
}
}

View File

@@ -32,4 +32,11 @@ class Test1 {
interface Bar {
Integer _(String s);
}
}
}
class Test2 {
void foo(Integer i) {}
<error descr="Incompatible types. Found: '<method reference>', required: 'java.lang.Object'">Object o = Test2::foo;</error>
}

View File

@@ -0,0 +1,21 @@
class MyTest {
interface I {
abstract void m1(int i);
}
static class A {
void m(int i) {}
}
static class B extends A {
void m(int i) {
I mh = super::m;
mh.m1(i);
}
}
public static void main(String[] args) {
new B().m(10);
}
}

View File

@@ -0,0 +1,13 @@
class MyTest {
interface I {
void _(MyTest receiver, Integer i);
}
void m(Integer i) {}
public static void main(String[] args) {
I i = MyTest :: m;
i._(new MyTest(), 1);
}
}