UUID not so unique

Put your problem here if it does not fit any of the other categories.

UUID not so unique

Postby bluef » Tue Jan 05, 2010 12:19 pm

Hello,

I'm facing an issue in using th UUID class, to get a unique ID...

I have a class, called "myObject" define like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class myObject {
  3.  
  4.         private static String ID;
  5.  
  6.        
  7.  
  8.         public myObject(){
  9.  
  10.                 ID = UUID.randomUUID().toString();
  11.  
  12.         }
  13.  
  14.  
  15.  
  16.         public String getID() {
  17.  
  18.              return this.ID;
  19.  
  20.         }
  21.  
  22. }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


And in the main class, I tried to do this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.     public static myObject m1 = new myObject();
  3.  
  4.     public static myObject m2 = new myObject();
  5.  
  6.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


When I look at the m1.getID() and m2.getID(), the both have exactly the same ID !!!!

Does anyone have an idea ??

Thanks in advance...

Regards,
Nek.
bluef
Developer
Developer
 
Posts: 33
Joined: Thu Nov 19, 2009 9:45 am

Top

Postby hardcoras » Tue Jan 05, 2010 3:01 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private static String ID;
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Your ID is declared as static. Remove static declaration.
hardcoras
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia

Postby bluef » Tue Jan 05, 2010 4:12 pm

Aaarrrggg.... :oops:

You're right... Sorry for this Java newbie question (and not Adnroid)..... :oops: Shame on me...

Thanks a lot !!!
bluef
Developer
Developer
 
Posts: 33
Joined: Thu Nov 19, 2009 9:45 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 17 guests