summaryrefslogtreecommitdiff
path: root/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/methodRef/MethodRefMisc1.java
blob: bd9c9ca188d951f44b99e610f1b24f1211a33266 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import java.util.*;
class MyTest {

   static void m(int i) {//here 
   }
   static void m(Integer i) {}

   interface I {
       void m(int x);
   }

   static void call(I s) { s.m(42); }

   public static void main(String[] args) {
       I s = MyTest::m;
       s.m(42);
       call(MyTest::m);
   }
}

class MyTest1 {

    static void m(Integer i) { }

    interface I1 {
        void m(int x);
    }

    interface I2 {
        void m(Integer x);
    }

    static void call(int i, I1 s) {
      
    }
    static void call(int i, I2 s) {
      //here
    }

    public static void main(String[] args) {
        call<error descr="Ambiguous method call: both 'MyTest1.call(int, I1)' and 'MyTest1.call(int, I2)' match">(1, MyTest1::m)</error>;
    }
}

class MyTest2 {

    static void m(Integer i) { }

    interface I {
        void m(int x);
    }

    static void call(int i, I s) {   }
    static void call(Integer i, I s) {   }

    static void test() {
        call(1, MyTest2::m); //call(int i, I s)
    }
}

class MyTest3 {
    interface I {
       void m();
    }

    MyTest3() {}

   static void m() { }

   public static void main(String[] args) {
      I s = <error descr="Static method referenced through non-static qualifier">new MyTest3()::m</error>;
   }
}

class MyTest4 {

    interface I {
        MyTest4 m(List<Integer> l1, List<Integer> l2);
    }

    MyTest4 meth(List<Integer>... lli) { return null; }
    MyTest4(List<Integer>... lli) { }

    I s1 = this::meth;
    I s2 = MyTest4::new;
}

class MyTest5 {
    interface I_void<X> {
        void m();
    }
    
    interface I_Void<X> {
        void m();
    }
    
    static void m_void() {}
    
    static Void _Void() {return null; }
    
    public static void main(String[] args) {
        I_void s1 = MyTest5::m_void;
        s1.m();
        I_Void s2 = MyTest5::m_void;
        s2.m();
        I_void s3 = MyTest5::_Void;
        s3.m();
        I_Void s4 = MyTest5::_Void;
        s4.m();
    }
}
class MyTest6 {
    interface I {
        MyTest6 invoke();
    }
    
    MyTest6() {
    }
    
    static MyTest6 m() {
        return null;
    }

    public static void main(String[] args) {
        I I1 = ((I)() -> {return null; })::invoke;
        I1.invoke();
        I I2 = ((I)MyTest6::new)::invoke;
        I1.invoke();
        I I3 = ((I)MyTest6::m)::invoke;
        I1.invoke();
    }
}

class MyTest7{
    
    interface I<R> {
        R invoke();
    }
    
    @interface A { }

    static abstract class AC { }
    
    enum E { }
    
    void test() {
        <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest7.I'">I s1 = A::new;</error>
        <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest7.I'">I s2 = I::new;</error>
        <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest7.I'">I s3 = AC::new;</error>
        <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest7.I'">I s4 = E::new;</error>
    }
}

class MyTest8{

    static class Sup {} 


    static class Sub extends Sup {

        interface I { Sup m(Sup x, String str); }

        class Inner extends Sup {
            Inner(String val) { }
        }

        void test() {
            <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest8.Sub.I'">I var = Sub.Inner::new;</error>;
        }
    }
}

class MyTest9 {
    
    static class SuperFoo<X> { }

    static class Foo<X extends Number> extends SuperFoo<X> { }
    
    interface I1 {
        void m();
    }

    interface I2 {
        void m();
    }
    
    static <X extends Number> Foo<X> m() { return null; }
    
    static void g1(I1 s) { }
    static void g2(I1 s) { }
    static void g2(I2 s) { }

    void test() {
        g1(MyTest9::m);
        g2<error descr="Ambiguous method call: both 'MyTest9.g2(I1)' and 'MyTest9.g2(I2)' match">(MyTest9::m)</error>;
    }
}