Method[] me = clazz.getDeclaredMethods();
for (Method method : me) {
System.out.println(method.getName().toUpperCase().toLowerCase());
}
涉及的知识有个专业名词,叫方法链,其实就是前一个方法返回一个对象,后一个方法是该对象的方法,从而可以使用点构成链,好处在于减少了中间变量的使用
其实你没必要想的那么复杂,例如:method.getName().toUpperCase().toLowerCase()。method.getName()是Method的方法没错,但是他的返回值应该是name字符串对吧,然而.toUpperCase()这个方法的使用需要一个字符串,对吧,所以你完全可以把method.getName()看成是一个具体的字符串,例如“张三”.toUpperCase()这样你应该就可以看的舒坦了,其实method.getName()也是一个字符串,后面的toLowerCase()也是这个道理。
注意一下,你获得的是一个字符串,也就是一个String对象,自然能调用String方法,调用toUpperCase()后,返回的还是一个字符串(也就是String对象),自然还能继续调用String的方法,相当于返回值继续调用方法,如果调用无返回值的方法后面自然调用不了了,
System.out.println(method.getName().toUpperCase().toLowerCase());
相当于String name1=method.getName();
String name2=name1.toUpperCase();
String name3=name2.toLowerCase();
System.out.println(name3);
应该不难理解吧?只是一种省略的写法了。