![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programmer
|
for(int i=0;i<points.size();i++)
{
g.fillOval(
((MyPoint)points.get(i)).x,
((MyPoint)points.get(i)).y,
dotSize, dotSize);
}try that JD |
|
|
|
|
|
#12 |
|
Programmer
Join Date: Nov 2004
Posts: 84
Rep Power: 4
![]() |
Why would he want to do that?
![]()
__________________
HijackThis Team-SFDC |
|
|
|
|
|
#13 |
|
Programmer
|
are you asking because you don't know, or because you think he should know?
haha ![]() JD |
|
|
|
|
|
#14 |
|
Programmer
Join Date: Nov 2004
Posts: 84
Rep Power: 4
![]() |
I'm asking because he doesn't know, which is why I suggested that he read the API instead of just giving him code.. then he may have been able to figure out on his own how to create the constructor, which libraries were necessary, and why one needs to do what you told him to do. And if not, he would have had questions about reading APIs, which would have allowed him to learn more on his own.
So to answer your question, I asked because I think he should know why you are recommending that he do what you said to do. Otherwise the next time that he goes to .get something, he will be stuck again, having learned nothing now. ![]() If it were me, I would have explained that an arraylist is really just a list of pointers that point to objects in memory, and it has no idea what kind of objects that they are. In order to use those objects, one must cast the object (which is just a way of telling the arraylist what it is) back into what they originally were so that the arraylist knows what to do with them. This is a crude (and not completely correct) explanation, but usually enough to make people understand. I would also explain that depending on the version of java one is using, and that since it is bad practice to store more than one datatype in a single collection, one can save themselves the trouble of having to tell the arraylist what it is removing each time by telling it ahead of time what sort of objects it will be holding, and one can do that (for example), in the following manner: ArrayList<myObject> a = new ArrayList(); Now my arraylist knows it is only going to hold myObjects, and won't let you put anything else in there but myObjects. It will always know what to do with them. ***** But that is just me... ![]()
__________________
HijackThis Team-SFDC |
|
|
|
|
|
#15 |
|
Programmer
|
uhh....yea, what he said
JD ![]() (ps - if you don't understand, research 'casting' and look at the API for arraylist) |
|
|
|
|
|
#16 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 149
Rep Power: 3
![]() |
Ah thank you all, it finally works. Seeing those dots appear is a beautiful sight...
I knew it had to do with the fact that I didn't specify what type of object was going to be in the ArrayList, but I didn't know how to specify that. But now I do, so it's all good =) |
|
|
|
|
|
#17 | |
|
Expert Programmer
|
Quote:
|
|
|
|
|
|
|
#18 |
|
Professional Programmer
|
Integer is int.
|
|
|
|
|
|
#19 |
|
Expert Programmer
|
No, one is a basic data type and the other is an object.
|
|
|
|
|
|
#20 |
|
Programmer
Join Date: Nov 2004
Posts: 84
Rep Power: 4
![]() |
There are a couple of approaches that I can think of, but all of them require some sort of conversion, whether it is handled by the programmer, or by the JVM, the conversions are still taking place. And it could very well be that I don't have a clue as to what I am talking about.. in which case this is an opportunity for me to learn also.
![]() You can use autoboxing, which only means that the conversion is done for you. It is still happening, and it may or may not be very efficient. You can create your own add/get methods that do the conversions for you. How big of a list of are you wanting to handle? Over a million? 3 million? A billion? Maybe there is an alternate means of doing what you want to do. All in all, the conversions don't take hardly any time, and I can't think of any way right off that one could seriously optimize the process.
__________________
HijackThis Team-SFDC |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|