Monday 15 August 2011

Java reflection with unique id -


I am trying to create a hashmap that its keys are unique IDs and the value is the name of the squares found by reflection is.

My problem is to create those unique IDs. How can I be strong that each class has unique ID, and this ID will never change. I mean, if I create a new class, it will never replace old class ID.

UPDATE
I need that the ID will be an integer number. (Sorry I have not mentioned this: P)

It guarantees to be completely unique But using the fully qualified class name should be enough. The full path of the string , such as java.lang.Math will be a good "unqiue" id, and should rarely be a hash collision.

Example

  map.put (MyClass.class.toString (), MyClass.class);   

Edit: If you need required , this is an integer, you can always use string hashod

  Map.put (MyClass.class.toString () .hashode (), MyClass.class);    

No comments:

Post a Comment