× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



The other option is to subclass Vector and provide your own get routine, like 
so:

public class FieldList extends Vector
{
    public Field fieldAt(int i)
    {
        return (Field) elementAt(i);
    }
}

This way, you hide the casting within the FieldList object.  Then you can say:

FieldList fields = new FieldList();
fields.addElement(new Field());
(...)

Field field = fields.fieldAt(i);

Joe

P.S. Note, you can also add a method addField to make sure that you always add 
the right kind of object.  However, if you're really afraid of the class having 
the wrong type of object added, you'd be better off doing it the way you did, 
by containing a Vector inside your FieldList class and then only exposing the 
methods you need.

---------- Original Message ----------------------------------
From: "Stone, Brad V (TC)" <bvstone@taylorcorp.com>
Reply-To: JAVA400-L@midrange.com
Date: Fri, 16 Mar 2001 14:53:59 -0600

>Thanks, makes a lot of sense.  Whenever I cast something I feel like I'm
breaking a rule.  And probably am.

By typed vectors I assume you mean something like:

Vector myClass = new MyClass() (or is it the other way.. it's friday, my
brain is oo'd out).

That would automatically create a vector of MyClass() objects.  I would like
to see the same thing.

As for using my own class instead of a vector, that means I need to make my
own size() and get() methods for it, correct?  That's what I've been doing.
For example:

  public int size()
  {
     return this.myList.size();
  }

Thanks again.

Brad

+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.