A couple of Bugs
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Tue Jun 7 02:58:57 PDT 2011
On 07/06/11 10:17, Ali Ebrahimi wrote:
> 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.
One method is static and generic, the other method is
non-static/non-generic. Since the invocation contains the explicit
type-arguments, JDK 6 compiler only sees the static/generic method - on
the other hand, JDK 7 doesn't have this restriction and sees both
methods as potentially applicable.
Try this:
class Array<X> {
public static <A> Array<A> array(final A... a) {
return null;
}
public X[] array() {
return null;
}
}
class Test {
static void test() {
Array.<String>array(); //ok with JDK 6, fails with JDK 7
Array.array(); //static error here in both JDK 6/JDK 7
}
}
Maurizio
>
> 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
> <mailto: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