How to differentiate between objects | do objects have ids

Started by
15 comments, last by Lactose 6 years, 10 months ago

Yeah it's actually a copy-paste bug in your first code snippet that's thrown you off. Look at this bit:


Players_DB Player = new Players_DB();
list_Players_DB.add(Player);
Players_DB Player1 = new Players_DB();
list_Players_DB.add(Player);
list_Players_DB.add("hmm");

Notice how you add Player twice and Player1 is created but not added?

It should have been this:


Players_DB Player = new Players_DB();
list_Players_DB.add(Player);
Players_DB Player1 = new Players_DB();
list_Players_DB.add(Player1);
list_Players_DB.add("hmm");

And you would get the result you expected!

Advertisement

I'm not sure which of the two approaches to take..

your method:

List<Players_DB> players = new ArrayList<Players_DB>();
players.add( new Players_DB());

mine:
List list_Players_DB = new ArrayList();
Players_DB Player = new Players_DB();
list_Players_DB.add(Player);


They basically the same approach except that you create player as a local variable whereas I didn't bother because it's only going into the list. They're equivalent for this purpose. If you want to further utilise the player variable in ways other than just adding it to a list then stick with your approach.

You really should be using the <angle brackets> from my version however. These are called generic parameters (fairly advanced concept, learn about it later), but for now you just have to know that they're an important part of writing modern Java code and will save you from bugs and help keep your code clean from unnecessary "type casting".

They're all regarding java, and can be boiled down to reveal many similarities, how ever they are not the same. If you are not going to contribute to the topic then don't post. You are trying to be helpful, how ever let me help you understand that I am browsing the web while creating threads because it's things I've found on the web that don't make sense, specifically mentioned above regarding multidimensional arrays requiring the same data type which is when someone in that thread (not my thread) recommended referencing objects in arrays instead. So I'm not being lazy, or trying to make your day a little more difficult by scrolling by an additional 400 pixels to find a post worthy of your assistance. I'm trying to learn Java. So far this works for me.

Instead of getting all defensive and condescending, you might want to consider the possibility that my post was a suggestion worth taking to heart.

Putting aside for the moment that some of the threads could easily have been consolidated/merged (2 threads with questions regarding constructors, one of which is named "Constructor questions" seems fairly redundant, to name a quick example), the main point is something different entirely.

You are trying to learn a programming language. While doing so, you are posting many threads on subjects -- some fairly similar, some quite different -- in a very short time period. This, to me, is a strong indication that you are trying to progress too quickly; that you are moving onto new topics without having an adequate understanding of the stuff you're moving away from. There's nothing wrong with asking questions or creating threads, but with your current post frequency it doesn't seem like you're giving yourself enough time to digest and comprehend the things you are studying.

I think your time would be better invested by slowing down a bit and allowing yourself a greater opportunity to fully understand the subjects you are reading.

It might also be worth pointing you towards the chat room for questions which you might feel aren't big/substantial enough for them to warrant their own thread. It can also be quite helpful if you need clarifying something quickly, or help spotting a bug in a piece of code.

Edit: Or, you know, act like you know better even when asking for help, and down-vote in spite. That will also work.

Hello to all my stalkers.

Apologies for helping derail this topic but: I find it odd you are derailing a topic with a huge wall of text like that. There is nothing wrong with what he is doing, he is clearly learning in a very practical manner and you shouldn't dictate how people learn. A forum is also easier to reference than chat logs. GDnet doesn't(I hope) have an issue with 6 threads per day being created per account.

I down-voted you not because I disagree (It would be nice if he had the fundamentals down) but because you are essentially telling someone not to use the forum to seek help.

 

Engineering Manager at Deloitte Australia

People are welcome to use the forum to seek help, but posting multiple threads at the same time on overlapping topics is the wrong way to do things. It means that anyone who wants to help has to try and follow each of those threads to understand what is being attempted. I appreciate that it can be frustrating when you're keen to make progress on your program and you have a lot of things that you want answers for, but the best approach is to post one clear thread, wait for the responses, act on them, and repeat.

3 hours ago, CRYP7IK said:

you shouldn't dictate how people learn.

What I posted was a suggestion that he should consider doing things differently. I think my reasons for suggesting it was made clear in my previous post (which was a "huge wall of text" in order to clarify the much shorter post which just got a dismissive and condescending reply).

I did not forbid him from creating 6+ threads per day, nor did I tell him to swap to only using the chat instead of creating threads. I said that he might want to reconsider his approach (with, I think, good reasons why), and I mentioned the chat existing because it can be helpful in ways the forum is not, due to its more direct nature.

Hello to all my stalkers.

This topic is closed to new replies.

Advertisement