java - how do i use reflection to find the class member name for an ArrayLIst that is used in the class, example? -


how can use reflection determine variable passed method?

example

public class exampleclass {    // class member variables   arraylist<string> strarrayone;   arraylist<string> strarraytwo;    //constructor   public exampleclass()[     strarrayone = new arraylist<string>();     strarraytwo = new arraylist<string>();   }      // create instance of nested class passing in required arraylist in constructor    nestedinnerclass testinstance = new nestedinnerclass(strarrayone);    // nested inner class   public class nestedinnerclass{      // class member variable     arraylist<string> memberarray = new arraylist<string>();      // constructor     public nestedinnerclass(arraylist<string> inputarray){       memberarray = inputarray;        // put code here determine reflection of       // 2 outer class variables being passed in strarrayone or strarraytwo?     }    } // end nested inner class  } // end outer class 

don't need reflection that. it's enough check equality of passed array , enclosing class's fields:

if (arrays.equals(inputarray, exampleclass.this.strarrayone)) {   // first 1 has been passed }  if (arrays.equals(inputarray, exampleclass.this.strarraytwo)) {   // second 1 has been passed } 

Comments