Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #16146
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
|---|---|
| From | clusardi2k@aol.com |
| Newsgroups | comp.lang.java.programmer |
| Subject | How to not use casting to invoke the methods of a List of objects |
| Date | Fri, 20 Jul 2012 06:58:49 -0700 (PDT) |
| Organization | http://groups.google.com |
| Lines | 22 |
| Message-ID | <61dca380-4364-4713-aa27-e885f96632ea@googlegroups.com> (permalink) |
| NNTP-Posting-Host | 198.151.13.60 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | posting.google.com 1342792729 11206 127.0.0.1 (20 Jul 2012 13:58:49 GMT) |
| X-Complaints-To | groups-abuse@google.com |
| NNTP-Posting-Date | Fri, 20 Jul 2012 13:58:49 +0000 (UTC) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=198.151.13.60; posting-account=r24XpwkAAABfAJg5TJRsTScS4AL5MjOT |
| User-Agent | G2/1.0 |
| X-Received-Bytes | 1744 |
| Xref | csiph.com comp.lang.java.programmer:16146 |
Show key headers only | View raw
Below uses a List of objects of class Route. Class Route has public member variables (such as locationid) and public methods (such as get_locationid()). The below code is a first attempt at a way to obtain the value of locationid using casting. Question: What is the code to do it a better way.
((Route)objList.get(0)).locationid;
((Route)objList.get(1)).locationid;
The below start of replacement code fails because it skips through the list. There wasn't a good reason for me to finish the code! The loop can't even iterate the required number of loops.
Iterator <Route> it = objList.iterator();
int size = objList.size();
for (int i = 0;i < size; i++)
{
it.next();
}
Thank you,
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
How to not use casting to invoke the methods of a List of objects clusardi2k@aol.com - 2012-07-20 06:58 -0700
Re: How to not use casting to invoke the methods of a List of objects markspace <-@.> - 2012-07-20 07:21 -0700
Re: How to not use casting to invoke the methods of a List of objects clusardi2k@aol.com - 2012-07-20 08:09 -0700
Re: How to not use casting to invoke the methods of a List of objects Joerg Meier <joergmmeier@arcor.de> - 2012-07-20 17:45 +0200
Re: How to not use casting to invoke the methods of a List of objects Robert Klemme <shortcutter@googlemail.com> - 2012-07-20 18:03 +0200
Re: How to not use casting to invoke the methods of a List of objects Joerg Meier <joergmmeier@arcor.de> - 2012-07-20 18:59 +0200
Re: How to not use casting to invoke the methods of a List of objects Roedy Green <see_website@mindprod.com.invalid> - 2012-07-20 21:22 -0700
Re: How to not use casting to invoke the methods of a List of objects Lew <noone@lewscanon.com> - 2012-07-21 23:34 -0700
csiph-web