groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Harvey <nathanwhar...@gmail.com>
Subject Re: About the native-lambda branch
Date Sat, 13 Jan 2018 03:07:26 GMT
Sure thing. Here's a Java example:

	void sample(Function<String, Integer> fn) {
		System.out.println("fn");
	}

	void sample(Supplier<Integer> sp) {
	    System.out.println("sp");
	}

These methods can exist side by side, and are called correctly even in cases
of Lambda, eg:

sample(s -> 123); // fn
sample(() -> 123); // sp

On the other hand, take this Groovy code:


​def sample(Function<String, Integer> fn) {
    println "fn"
}

def sample(Supplier<Integer> sp) {
    println "sp"
}


With attempted invocation:

sample({ s -> 1 })​

This produces an error: 

Cannot resolve which method to invoke for [class Script1$_run_closure1] due
to overlapping prototypes between:
	[interface java.util.function.Function]
	[interface java.util.function.Supplier]



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Mime
View raw message