问题:作业

By Myself...发布 问题来源
public class Main { public static void main(String[] args) throws Exception { Person p1 = new Person("Xiao Ming", 25, "100123"); Person p2 = new Person(null, 15, "8080k"); _checkPerson_(p1); _checkPerson_(p2); } static void checkPerson(Person p) throws Exception { System.**_out_**.println("check " + p + "..."); Class<?> c = Person.class; for (Method m : c.getMethods()) { _checkMethod_(m, p); } } static void checkMethod(Method m, Person p) throws Exception { if (m.isAnnotationPresent(_NotNull_.class)) { if (m.invoke(p) == null) { System.**_out_**.println("Error: method " + m.getName() + "()的返回值是null."); } } if (m.isAnnotationPresent(_Range_.class)) { _Range_ range = m.getAnnotation(_Range_.class); if (m.invoke(p) == null) { System.**_out_**.println("Error: method " + m.getName() + "()的返回值是null."); } else if (m.getReturnType().equals(String.class)) { String result = (String) m.invoke(p); int length = result.length(); if (length >= range.max() || length < range.min()) { System.**_out_**.println("Error: method " + m.getName() + "()的返回值超过了Range"); } } else if (m.getReturnType().equals(int.class)) { int result = (int) m.invoke(p); if (result > range.max()) { System.**_out_**.println("Error: method " + m.getName() + "()的返回值超过了Range"); } } } if (m.isAnnotationPresent(_ZipCode_.class)) { _ZipCode_ zipcode = m.getAnnotation(_ZipCode_.class); String result = (String) m.invoke(p); if (result.length() != zipcode.value()) { System.**_out_**.println("Error: method " + m.getName() + "()的返回值长度与value不符"); } if (!_isNumeric_(result)) { System.**_out_**.println("Error: method " + m.getName() + "()返回值不全由数字组成."); } } } public static boolean isNumeric(String str) { for (int i = str.length() - 1; i >= 0; i--) { if (!Character._isDigit_(str.charAt(i))) { return false; } } return true; } }
  • 1

您当前正在使用不支持HTML5的低版本浏览器,飞扬学院需要支持HTML5的浏览器才能为您提供更好的学习体验。请使用支持HTML5的Chrome浏览器Firefox浏览器或最新版本的IE浏览器