Re: Way to convert List object to class object
GArlington wrote:
On 27 Sep, 04:15, joethara...@gmail.com wrote:
hi
I was trying to acces a class using a List object in a different
class. I want the object to have the same features as LIst object but
the same time have acces to a different class in the same project.
thanks
joe
Are you trying to extend two classes? This is NOT possible...
You can extend ONE class AND implement MANY interfaces...
Or maybe you can find these useful:
http://forum.java.sun.com/thread.jspa?threadID=544569&messageID=2646191
http://www.artima.com/designtechniques/compoinh.html
I didn't read "have access to" as "inherit from", but as "use". The OP also
mentioned List, which /is/ an interface.
To the OP:
You place the List reference into a variable, e.g.,
List<Foo> something = new ArrayList<Foo>();
This can be any kind of variable: class, instance, local.
You pass the variable into a method of your other class, e.g., class Bar:
Bar bar = new Bar();
bar.someMethod( something );
Now the Bar someMethod() can operate on the argument:
public class Bar
{
public void someMethod( List<Foo> inVar )
{
// do some processing on inVar
}
}
Note that both the invoking class and the Bar class have to be "aware" of the
types List and Foo.
--
Lew