dimanche 2 décembre 2018

Persist method argument names in bytecode so that they are available through reflection when building with Maven

To use from reflection I need to store info about method parameters

It's possible to do it manually from eclipse by following (Window -> Preferences -> Java -> Compiler)

But how can I enable this through maven build

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

public class GetParams {

       public static void main(String[] args) throws Exception {
             Method method = MyInterface.class.getMethod("myway", String.class);
             Parameter p = m.getParameters()[0];
             System.out.println(p.isNamePresent());
             System.out.println(p.getName());
        }  

        public interface MyInterface {
             String myway(String str);
        }  
  }





Aucun commentaire:

Enregistrer un commentaire