Hey all =)
The title might not be what I really mean and for that I apologize..
I'm asking this because its something that came up in a conversation I had with a colleague in my programming class
Lets say I have this Class:
public class Planet{ int planetID; public Planet(int pID){ planetID = pID; } public String toString(){ return new Integer(planetID).toString(); } }
and this one:
public class Testing{ public static void main(String args[]){ Planet mercury = new Planet(0); System.out.println(mercury); //I know that this will return "0" Planet[] pArray = new Planet[9]; pArray[mercury] = mercury; //This is where my question lies }
Saying in words, is it possible to use the implicit toString() every class has to directly return an int to make it usable in array indexing?
I've already tried brainstorming with my colleague, and what we got was using something like(using above example):
pArray[new Integer(mercury.toString())] = mercury;
Is there an easier way to do this or is this simply stupid?