Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot access object's methods from inside ArrayList  RSS feed

 
Jacob Morehouse
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!


I've done this before, I cannot figure out what I am missing. In short, I can access an objects methods (like gets and sets) while it is just an object, but when I put it into a structure like an ArrayList I cannot access those methods.

The class:


Now the main:


It has been awhile since I've done anything with Java, what am I doing wrong here? I'm sure it is something simple but I'm about 6 hours in and still no solution. Any help would be appreciated.

Thanks!
Jake
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a tutorial that will bring you up to speed.
 
Jacob Morehouse
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Darryl,


I'll take from your vague post that this forum isn't friendly to entry level questions. Is there another forum (or site entirely) you would recommend I post this question? I feel like we're already off to a trolled start and neither of us is adding value to this forum at this point.


Thanks
 
Jacob Morehouse
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear, moving in the right direction now.
 
Jacob Morehouse
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it. In case anyone else Googles it and finds this post. It had nothing to do with generics, everything to do with objects/classes. I changed my main:

If you Googled and got here, hopefully you didn't waste time on generics on your way to my answer.


Jake
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jacob

In fact changing your code to use array is one solution, but using generics can surely make life easier for large collections.


 
Jacob Morehouse
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Hi Jacob

In fact changing your code to use array is one solution, but using generics can surely make life easier for large collections.



Thank you for posting - I would consider your solution superior as well, you don't have to define the exact length of the array which is also good.

To verify I understand, <People> is casting the "type" of the array to "People"?

Jake
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Morehouse wrote:Hi Darryl,


I'll take from your vague post that this forum isn't friendly to entry level questions. Is there another forum (or site entirely) you would recommend I post this question? I feel like we're already off to a trolled start and neither of us is adding value to this forum at this point.


Thanks


I fail to see how you could read posting a link to the Generics tutorial as not friendly or vague. The better solution to your question does lie in using Generics -- as again pointed out by K. Trang, more than two hours after my post -- which would have given you enough time to go through the tutorial and discover how to solve your problem.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Morehouse wrote:Got it. In case anyone else Googles it and finds this post. It had nothing to do with generics, everything to do with objects/classes.

If you Googled and got here, hopefully you'll read the entire thread and follow any links to learning resources, from which you will conclude that this has everything to do with Generics.
 
Jacob Morehouse
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
Jacob Morehouse wrote:Got it. In case anyone else Googles it and finds this post. It had nothing to do with generics, everything to do with objects/classes.

If you Googled and got here, hopefully you'll read the entire thread and follow any links to learning resources, from which you will conclude that this has everything to do with Generics.

You found your post not to be vague? I understand how your feelings might be a little bruised here, but a post like your first one holds very little value not because you were incorrect, but because you made no effort to support your claim. I realize your attempt was to get me to look up generics, but a comment like yours on the Internet just gets immediately ignored as another troll. A comment like K. Tsnag's gets me looking up generics.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jacob,

What Darryl in the very beginning actually point you to the right direction letting you research about generics. You may not notice or realize the usefulness of generics when reading at first. Learning generics at first is indeed a bit hard.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob

You will find on most forums that answers to questions generally include links to tutorials to further your understanding. How you find this vague or unhelpful is beyond me to be honest.
 
Tony Docherty
Bartender
Posts: 3268
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jacob,

It would appear that there's has been a misunderstanding. This site is incredibly friendly and the staff (of which Darryl is one) work hard to ensure it stays that way. We are all volunteers here freely giving our time, knowledge and experience to help people like yourself solve their problems.

If Darryl's post was brief it may be because he didn't have time to write more and felt that giving you a link so you could help yourself was a suitable initial answer. I'm sure there was no intent on his behalf to be rude or dismissive.

The answer clearly wasn't what you were hoping for and you have over reacted to it but thanks for keeping your response civil. Hopefully you will spend some time looking around the site and see this has just been a misunderstanding and you will want to be part of this great community.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!