Java Generics with Wildcards Not Compiling -


i'm having trouble understanding finer points of java generics wildcards. specifically, why doesn't compile.

public class test {      abstract class function<a, b> {         abstract b call(a a);     }      interface propertytype {         string bubbles();     }      class apartment implements propertytype {         @override         public string bubbles() {             return "bubbles";         }     }      public void invokefunctiononalist() {         list<apartment> apts = new arraylist<apartment>();         functionloop(apts, new function<apartment, string>() {              @override             string call(apartment a) {                 return a.bubbles();             }         });     }      public void functionloop(list<? extends propertytype> list, function<? extends propertytype, string> t) {         (propertytype p : list) {             t.call(p);         }     } } 

your compiler not know if using same type in list , function. therefore have tell him this.

try this:

public <c extends propertytype>void functionloop(                          list<c> list, function<c, string> t) {   (c p : list) {     t.call(p);   } } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -