primary key für java klasse?

Sowas wie ne id bekommst wie folgt:

Java:
public class Main {

   public static void main(String[] args) {
     IDObject io = new IDObject();
     System.out.println(System.identityHashCode(io));
     IDObject io2 = new IDObject();
     System.out.println(System.identityHashCode(io2));
   }

}
class IDObject {
   private String blub;
   private String blob;
   public String getBlub() {
     return blub;
   }
   public void setBlub(String blub) {
     this.blub = blub;
   }
   public String getBlob() {
     return blob;
   }
   public void setBlob(String blob) {
     this.blob = blob;
   }
  

}

Und was google noch dazu sagt:
Uniqueness isn't necessarily guaranteed, note. The Sun JVM implementation will give you a value which is related to the original memory address for this object, but that's an implementation detail and you shouldn't rely on it.

Viele Grüße
Youza
 
Zurück