Here's my current code
package myPackage;
public class Server {
public static void main(String[] args) {
int Arr_Players_DB[] = new int [5]; //array object initialization
for (int i = 0; i < Arr_Players_DB.length ; i ++)
{
Arr_Players_DB[i] = -1; //Initialize array
}
for (int i = 0; i < Arr_Players_DB.length; i ++) // //populate array
{
Players_DB player = new Players_DB();
if (Arr_Players_DB[i] == -1)
{
Arr_Players_DB[i] = player;
}}}}
Why are you trying to store an object inside an array of integers? If you want to store an object into an array, the array needs to be declared with the same type as the object (or a supertype/interface of).
Also, what is the exact error message? If you are trying to store an object in an int array you should get an error saying that cannot assign object type to int or something similar, not that the object doesn't have an ID.
EDIT: also, related to the topic, you might find interesting to read about identity and equality in Java.
Error message is "Type mismatch: cannot convert from Players_DB to int"
Because I want a list, each list ID must be a reference to each object, each object holds variables which will equal to properties that I've assigned for each object. These will be for "Players" in the game in a server side application. So it makes sense that I should try and reference each object in an array.
The reason I've moved from using a 2D array for this is because Multidimensional Arrays in java require that each dimension be the same data type, which is a problem when I want to store "username String" and "password Integer"(for example).
I had a look at Identity and equality, all it's showing me is that objects can be referenced by creating a new object type and storing another object in that. Referencing yes..
So the idea then is when I create a new array
int Arr_Players_DB[] = new int [5]; //array object initialization
That the data type be that of an object, but that would work would it ?
You are posting a lot of threads, most of them on the same topic. Maybe it's time to slow down a little and work with tutorials and/or reading, instead of posting 6 threads in a single day?
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.
From what I've searched up on google people are creating libraries to find differences between objects, I just want to be able to identify objects. Or rather find out if an object has an id.
An object has a memory start address which is unique for each object. That is being used for identity checking (ie ==). The default implementation of "equals" also uses that (except for some standard objects like integers, reals, and strings, and such). By overriding "equals" you can have your own equality notion between objects. (However, given the kind of questions you ask, this is currently a little too far for now, so something to keep in mind for later.)
Edit: Sorry, I was talking total nonsense about equals: primitive types (int, double/float, and boolean) have no equals, and use == as equals. class-types (ie everything else than primitive types) have both == and equals, which may or may not check the same thing.
This is similar to the link provided by Avalandor, there's an image which shows that each object holds a space within memory. What's new is that you're saying they have unique start addresses, I don't think It's suppose to get that complicated to find these addresses just to make a list of objects that can be referenced.