java - How to get a unique method identifier? -


I need to get a unique method identifier to use as a key on a hashmap.

I am attempting to do something to use stacktrace and reflection and the user to use the method signature. But the problem is that I did not find any way to get back the signature (to avoid methods overload).

edit

I like that some things like this work:

  public class class 1 {Hashmap & Lt; String, Object & gt; Hm; Public Class 1 () {Hm = new Hashmap & lt; String, Object & gt; (); } Public Object Method () {if (! ContainKey ()) {Object Value; ... put (value); } Return (); } Public object method (string request 1) {if (! Contains any ()) {object value; ... put (value); } Return (); } Public boolean () (if (hm.containsKey (Util.getUniqueID (2)) {Back true;} Other {return false;}} Public zero entry (object value) {hm.put (Util.getUniqueID ( 2), value);} get the public object () {string key = Util.getUniqueID (2); if (hm.containsKey (key) {return hm.get (key);} else {return null;}}} Class Util {public static string getUniqueID (integer depth) {StackTraceElement element = Thread.currentThread (). GetStackTrace () [Depth]; return element.getClassName () + ":" + element.getMethodName ();}}   

But the problem is two ways, i

P> You can add + ": ++ element.getLineNumber () , but you should still be concerned about this matter where two overloaded D methods are placed in a long line.

StackTraceElement methods, it is not possible to obtain a unique method identifier in this way. Besides, the code is not very readable in my opinion.

I suggest that you try to be more clear and

  if (hm.containsKey ("getValue (Int)") {...}  

or something like that.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -