java - Unsafe or unchecked expressions in an arraylist -


i'm doing assignment , have create iterable collection saves values of binary tree between tresholds. binary tree class has root variable, object of treenode class i've written. nodes store integer values. here methods:

public class tree {     public iterable<integer> listing(int low, int high) {             arraylist<integer> list=new arraylist<integer>();                  return root.listing(lo, hi, list);         } }  public class treenode {     public arraylist<integer> listing(int low, int high, arraylist list) {         if(this.left!=null) {             list=this.left.listing(low, high, list);         }          if(this.value>=low && this.value<=high) {             list.add(this.value);         }          if(this.right!=null) {             list=this.right.listing(low, high, list);         }         return list;     } } 

it works fine locally, have upload platform uses java 6, , i'm getting error uses unchecked or unsafe operations. getting same message in ide, seems imply it's not of great importance. however, have fix in way. tried reading on unsafe/unchecked operations i'm not sure understand what's problem here. there way fix without changing whole code?

this isn't error, it's warning, but, noted, should fix it.

the problem you're passing unbound arraylist, that, theoretically, can hold elements of type, while you're dealing integers. so, instead, declare parameter arraylist of integers:

public arraylist<integer> listing(int low, int high, arraylist<integer> list) { 

edit:
way, there's no need have arraylist in method's declaration. since thing care here list interface , not it's implementation, can clear declaration bit:

public list<integer> listing(int low, int high, list<integer> list) { 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -