正常来说,应该是下面这种,但是我个人感觉很别扭(Normally, it should be the following, but I personally feel awkward)
Class c = stu.getClass(); Field nameField = c.getField("name"); nameField.set(stu, "tom");
为啥不写成下面这种(why not design directly like this):
Class c = stu.getClass(); c.set(stu,"name", "tom");
Aucun commentaire:
Enregistrer un commentaire