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
Knute Johnson - 27 Sep 2007 04:41 GMT
> 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
Huh?

Signature
Knute Johnson
email s/nospam/knute/
GArlington - 27 Sep 2007 15:21 GMT
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
Lew - 27 Sep 2007 15:29 GMT
> On 27 Sep, 04:15, joethara...@gmail.com wrote:
>> hi
[quoted text clipped - 9 lines]
> 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.

Signature
Lew
Roedy Green - 27 Sep 2007 23:15 GMT
>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
I read your sentence several times. I think you want to do this.
I want a object that has both the List methods and some others.
So you can either "implement List" or extend ArrayList or some other
List class. Then those objects will have all the List methods plus
any others you add. See SortedArrayList. Source is available from
http://mindprod.com/jgloss/products2.html#SORTED

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Daniel Pitts - 27 Sep 2007 23:23 GMT
On Sep 26, 8:15 pm, 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
public class MyList<T> extends AbstractList<T> implements List<T> {
DifferentClassInSameProject different;
public MyList(DifferentClassInSameProject different) {
this.different = different;
}
public void accessDifferent() {
different.doSomething();
}
// You have a little bit of implementing to do below.
// ...
}
Is that what you wanted?
Perhaps you'd get better answers if you asked us how to achieve a
certain goal, rather than how to do what you've determined will
achieve that goal.
HTH,
Daniel.
Lew - 28 Sep 2007 02:47 GMT
> public class MyList<T> extends AbstractList<T> implements List<T> {
The implements clause is redundant. AbstractList<T> already implements List<T>.

Signature
Lew
Daniel Pitts - 29 Sep 2007 07:02 GMT
> > public class MyList<T> extends AbstractList<T> implements List<T> {
>
> The implements clause is redundant. AbstractList<T> already implements List<T>.
>
> --
> Lew
I know its redundant, but its explicitly explains what the purpose of
MyList is.