Reference to array of objects in java -
before onto question, i'd give me specific advice because i've been searching long time can't seem find out correct answer. know it's basics having issues. have in code:
private interface classname; //initializing class implements interface public interface methodname () { /*this need make arraylist of objects of class , return whole class reference, maybe this:*/ list<interface> listname = new arraylist<>(perhaps needs number of objects added?); listname.add(classname); return classname; //or should done
and guess once call method use listname.get(number of object);
problem is, return list reference, method requires me return class said interface , not sure how reference class specific arraylist of objects , return in method.
thank time. i'll try explaining in plain english. first of all, it's assigement can't change ways methods given. way, not actual variable names, names clarify reffering to. explanation: /** * * gets {@link isystemregisters} object of current computer system. * * * * @return object representing system registers. */ public isystemregisters getregisters();
so have class different interface isystemregisters , method in supposed hold arraylist of objects (here registers) , return object reference in array is, understood it.
if want return list method, should declare method this:
public list<interface> methodname () { ... return listname; // instead of returning classname }
with list return type.
side notes:
your first line confusing, you're not initializing (as pointed out @lucas) declaring variable (a field here) of type
interface
classname
name (which shouldclassname
instead).no, don't need specify number of items @ list's creation. different arrays.
your variable names confusing, if end
name
, people think variable contains name. expectstring
s.
Comments
Post a Comment