Java Generic List Template -


i created listprinter (main class) , listholder class.

i taught how create generic arrayholder trying modify (my homework) list holder.

my teacher's array printer code is:

 public class arrayholder <p>  {     p arr[];     public void print(p arr2[],int count)     {         arr = arr2;          (int = 0; < count; i++)          {             system.out.print("\n"+arr[i]+"\n");        }// end     }// end print method }// end class. 

i used template listholder keep getting error in sout line:

public class listholder <x> {      x list ;          public  void print (x list2, int count)      {               list= list2;         (int = 0; < count;  i++)          {             system.out.print(list2(i)+"\n");         }     } // end print } //end class 

what doing wrong???

========== kaykay

it still giving me errors :( copied , pasted answer. first error on line: list list; first list underlined , error is: cannot find symbol

second error in line under that: public void print (list list2, int count) list underlined , error same = cannot find symbol

on list need use get(index) method retrieve element index.

also x type of list contains, not type of list itself. declaration should list<x> list.

here's code these modifications :

public class listholder <x> {      list<x> list ;          public  void print (list<x> list2, int count)      {               list= list2;         (int = 0; < count;  i++)          {             system.out.print(list2.get(i)+"\n");         }     } // end print } //end class 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -