Problem of defender methods with generic methods

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Nov 8 04:42:23 PST 2010


Hi Ali
this should be fixed now - it was a regression caused by recent work on 
extension methods.

Thanks for the report.
Maurizio

On 06/11/10 04:55, Ali Ebrahimi wrote:
> Hi Maurizio,
>
> when compiling the following code I get two error.
>
> public interface CustomizedList<T>  extends List<T>  {
>      extension CustomizedList<T>  filter(Predicate<T>  predicate) default
> Trait.<T>filter;
>      <R>  extension CustomizedList<R>  map(Extrator<T,R>  predicate)
> default Trait.<T,R>map;<========== cannot find symbol R
>      <A extends Comparable<? super A>>  extension A max() default
> Trait.<A>max;<=============  cannot find symbol A
>
>     public static class Trait {
>
>          public  static<T>  CustomizedList<T>  filter(
>                  final CustomizedList<T>  self, final Predicate<T>  predicate) {
>              CustomizedList<T>  result=null;
>              try {
>                  result = self.getClass().newInstance();
>              } catch (Throwable e) {
>                  e.printStackTrace();
>              }
>              for(T elm:self){
>                  if(predicate.op(elm))
>                      result.add(elm);
>              }
>              return result;
>          }
>
>          public static<T,R>  CustomizedList<R>  map(
>                  final CustomizedList<T>  self, final Extrator<T,R>  extrator) {
>              CustomizedList<R>  result=null;
>              try {
>                  result = self.getClass().newInstance();
>              } catch (Throwable e) {
>                  e.printStackTrace();
>              }
>              for(T elm:self){
>                  result.add(extrator.extract(elm));
>              }
>              return result;
>          }
>
>          public static<R extends Comparable<? super R>>  R max(
>                  final CustomizedList<? extends R>  self) {
>              if(self.size()==0)
>                  return null;
>
>              R result=self.get(0);
>              for(R elm:self){
>                  if(elm.compareTo(result)>0)
>                      result=elm;
>              }
>              return result;
>          }
>      }
> }
>
>
> Best Regards,
>
> Ali Ebrahimi
>
>    



More information about the lambda-dev mailing list