谁能澄清一下Head First Servlets & JSP下面的行概括了标签对象的属性存储行的含义吗? (第 555 页):
One solution would be to put all of the attributes into a hashtable. This generalizes the tag object's storage of attributes, but what about all these setter methods? We can't get rid of them unless there's a way to tell the JSP engine to set the tag attributes using a generic interface.
提前致谢。
最佳答案
在此上下文中,“概括”意味着您可以编写一个函数或一小段代码来实现所有案例,而不是单独编写每个案例。我没有那本书,但看起来它取代了类似的东西:
String attr1;
String attr2;
String attr3;
与
Hashtable<String, String> attributes;
这是对存储的概括 - 代码旨在显示将字符串映射到字符串的通用哈希表 - 您将使用类似的东西
attributes["attr1"] = "value";
其他代码的使用方式如下:
attr1 = "value";
关于java - "generalizes the tag object' s 存储”是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1121529/