<dependency> <groupId>com.thoughtworks.paranamer</groupId> <artifactId>paranamer</artifactId> <version>2.8</version> </dependency> groovy dependencies { implementation 'com.thoughtworks.paranamer:paranamer:2.8' } public class ExampleClass { @Named public void exampleMethod(String paramName) { // method implementation } @DontUseParanamer public void anotherMethod(int param1, int param2) { // method implementation } } import com.thoughtworks.paranamer.BytecodeReadingParanamer; import com.thoughtworks.paranamer.ParameterNamesNotFoundException; public class Main { public static void main(String[] args) { // Create an instance of BytecodeReadingParanamer BytecodeReadingParanamer paranamer = new BytecodeReadingParanamer(); // Get parameter names of a method String[] parameterNames; try { parameterNames = paranamer.lookupParameterNames(ExampleClass.class.getMethod("exampleMethod", String.class)); for (String paramName : parameterNames) { System.out.println("Parameter name: " + paramName); } e.printStackTrace(); } } }


上一篇:
下一篇:
切换中文