A couple of Bugs
Ali Ebrahimi
ali.ebrahimi1781 at gmail.com
Tue Jun 7 02:17:55 PDT 2011
Hi Maurizio,
No, I don't think so.
java 6 compiler correctly resolve this invocation to static varargs method.
In this case we have two array method in Test class, on static ( and
generic) with single varargs parameter that returns Array<A> and
other member method without any params that returns A[]. and compiler
incorrectly try to resolve two later once.
public static <A> Array<A> array(final A... a) {
return new Array<A>(a);
}
public A[] array() {
return null;
}
public static <A> Array<A> test() {
return Array.<A>array();
}
I think this clears Issue.
Best Regards
Ali Ebrahimi
On Tue, Jun 7, 2011 at 12:14 PM, Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:
> Hi Ali,
> the static error you are seeing is a result of the fix for 5081782 (type
> arguments to non-generic methods) - if you remove the explicit type-argument
> from the following invocation:
>
>
> public static <A> Array<A> test() {
> return Array.<A>array();
> }
>
> You get the very same error in JDK 6. Thus, the new error in JDK 7 is
> caused by the fact that the method Array.array() is not excluded anymore
> from overload resolution because of explicit type-arguments.
>
> The other is a problem with overload resolution and nested lambda
> expression, and will be fixed.
>
> Maurizio
>
>
>
> On 07/06/11 04:53, Ali Ebrahimi wrote:
>
>> class Test {
>>
>> static class Array<A> {
>> private A[] data;
>>
>> Array(A[] data) {
>> this.data = data;
>> }
>>
>> public static<A> Array<A> array(final A... a) {
>> return new Array<A>(a);
>> }
>>
>> public A[] array() {
>> return null;
>> }
>>
>> public boolean forAll(final F<A, Boolean> f) {
>> for (final A x : data)
>> if (f.f(x))
>> return true;
>>
>> return false;
>> }
>>
>> }
>>
>> public interface F<A, B> {
>> B f(A a);
>> }
>>
>> public static<A> Array<A> test() {
>> return Array.<A>array();
>> }
>>
>> public static Array<Character> fromString(final String s) {
>> List<Character> cs = Collections.emptyList();
>>
>> for (int i = s.length() - 1; i>= 0; i--)
>> cs.add(s.charAt(i));
>>
>> return new Array<Character>(cs.toArray(new Character[0]));
>> }
>>
>> public static void main(String[] args) {
>>
>> final Array<String> a = Array.array("Hello", "There", "what",
>> "DAY",
>> "iS", "iT");
>> final boolean b = a.forAll(#{String s -> fromString(s).forAll(#{
>> Character c -> isLowerCase(c)}) }); //***********
>> System.out.println(b); // true ("what" provides the only example;
>> try removing it)
>> }
>> }
>>
>
>
More information about the lambda-dev
mailing list