type inference problem lead to cannot find symbol error message

Rémi Forax forax at univ-mlv.fr
Sat Aug 7 11:33:32 PDT 2010


Le 07/08/2010 19:55, Thomas Jung a écrit :
> Hi,
>
> I'm still trying out functionality of the Guava library with the
> lambda prototype.
>
> This time I've a strange behavior with the
> CharMatcher.forPredicate(Predicate<? super Character>  predicate)
> method (http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/base/CharMatcher.html#forPredicate%28com.google.common.base.Predicate%29).
>
> If I remove the type of the predicate
>
> CharMatcher c = CharMatcher.forPredicate(#(Character c){c.compareTo('e')<  0});
> CharMatcher c2 = CharMatcher.forPredicate(#(c){c.compareTo('e')<  0});
>
> it results in the error message:
>
> CTest.java:[47,50] cannot find symbol
>
> [47,50] is the first opening brace "CharMatcher c2 = CharMatcher.forPredicate("
>
> Any ideas?
>
> Thomas
>    

For CharMatcher.forPredicate(#(c){c.compareTo('e') < 0});
c is infered as Object and so the compiler can not find 
Object.compareTo(...).

? super Foo as parameter should be the infered as Foo and not as Object.

Rémi


More information about the lambda-dev mailing list