Closed liuliuliu12138 closed 1 year ago
反射时用到的getter setter方法的构建方法实在太简单粗暴,不符合常规规范
public static StringBuilder capitalize(StringBuilder sb, String s) { if (s == null) { return sb; } else { sb.append(s.substring(0, 1).toUpperCase()); sb.append(s.substring(1)); return sb; } }
不论是是intelij idea默认的getter setter生成策略代码: https://github.com/JetBrains/intellij-community/blob/db4ae038643d134dfcf7199459ee8f5e0c2ac097/platform/util/src/com/intellij/openapi/util/text/StringUtil.java#L949
public static @NotNull String capitalizeWithJavaBeanConvention(@NotNull String s) { if (s.length() > 1 && Character.isUpperCase(s.charAt(1))) { return s; } return capitalize(s); }
亦或是java.beans.Introspector#decapitalize,都是会对前两个char进行判断
public class Introspector { public static String decapitalize(String name) { if (name == null || name.length() == 0) { return name; } if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) && Character.isUpperCase(name.charAt(0))){ return name; } char chars[] = name.toCharArray(); chars[0] = Character.toLowerCase(chars[0]); return new String(chars); } }
而从4.x升到5.x直接将getter setter方法的构建变为首字母大写这么简单粗暴,将直接导致类似于aBC这种命名的property反射失败,希望考虑与标准规范兼容!
Good catch! Sorry,我对这个规范研究不深。 我修复下。
Fixed in v5.4.0 https://github.com/killme2008/aviatorscript/releases/tag/aviator-5.4.0
反射时用到的getter setter方法的构建方法实在太简单粗暴,不符合常规规范
不论是是intelij idea默认的getter setter生成策略代码: https://github.com/JetBrains/intellij-community/blob/db4ae038643d134dfcf7199459ee8f5e0c2ac097/platform/util/src/com/intellij/openapi/util/text/StringUtil.java#L949
亦或是java.beans.Introspector#decapitalize,都是会对前两个char进行判断
而从4.x升到5.x直接将getter setter方法的构建变为首字母大写这么简单粗暴,将直接导致类似于aBC这种命名的property反射失败,希望考虑与标准规范兼容!