java-topology/test/langtools/tools/javac/lambda/methodReference/MethodRef_neg.java
russell@unturf.com 0a580b313d undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
2026-03-26 17:11:57 -04:00

36 lines
959 B
Java

/*
* @test /nodynamiccopyright/
* @bug 8003280
* @summary Add lambda tests
* This is negative test for wrong parameter/return type in method references
* @compile/fail/ref=MethodRef_neg.out -XDrawDiagnostics MethodRef_neg.java
*/
public class MethodRef_neg {
static interface A {void m(Integer i);}
static interface B {void m(String s);}
static interface C {Integer m();}
static interface D {String m();}
static void bar(int x) { }
int foo() {
return 5;
}
static void make() { }
void method() {
A a = MethodRef_neg::bar; //boxing on parameter type is ok
B b = MethodRef_neg::bar; //wrong parameter type, required: String, actual: int
C c = this::foo; //boxing on return type is ok
D d = this::foo; //wrong return type, required: String, actual: int
a = MethodRef_neg::make; //missing parameter
c = MethodRef_neg::make; //missing return type
}
}