|
Java example source code file (MethodRef_neg.java)
The MethodRef_neg.java Java example source code
/*
* @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
}
}
Other Java examples (source code examples)Here is a short list of links related to this Java MethodRef_neg.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.