当前位置:首页 » 软件开发
开发技术指南» 文章正文
    引言: Implementing equalsDiscussion:A
 

 

    摘要: 首先实现一个dbaccount类,完成数据库连接细节,这里使用的是mysql,你可以自行设计一个输入界面来获取用户输入的数据库连接参数:class dbaccount{ //数据库路径 string thedbname; //用户名 string theuserid; //帐户 string thepasswd; dbaccount(){ thedbname="jdbc:mysql:/......
 ·eclipse启动参数大全    »显示摘要«
    摘要: eclipse 运行命令行参数大全 包括英文版本和中文版本两种的说明, 特别需要值得一提的是那个 -nl 参数, 可以指定程序启动时所使用的语言. 例如:eclipse -nl en_us将启动英文语言, 这个特性在安装了国际化语言包以后特别有用, 可以方便的切换各个语言的版本. 注意 ibm wsad v5.1 也支持这个功能. 运行 eclipse将 eclipse 驱动程序安装(解压缩)到......


覆盖equals【引自http://www.javapractices.com/Topic17.cjp】
implementing equalsdiscussion:all objects have both identity (the objects location in memory) and state (the objects data). the == operator always compares identity. the default implementation of equals compares identity as well.

sometimes the default implementation of equals has the desired behaviour (as in a type-safe enumeration, for example), but  equals should usually compare state, not identity. this is particularly true for "data-centric" classes which map to database records.

if you override equals, you must override hashcode hashcode must generate equal values for equal objects objects placed in a list , set, or map (as either a key or value) should have an appropriate definition of equals. (see, for example, the javadoc for java.sun.com/j2se/1.5.0/docs/api/java/util/collection.html#contains(java.lang.object)">collection.contains , java.sun.com/j2se/1.5.0/docs/api/java/util/map.html#containskey(java.lang.object)">map.containskey, and java.sun.com/j2se/1.5.0/docs/api/java/util/map.html#containsvalue(java.lang.object)">map.containsvalue .)

if you extend a concrete class, and add a new field which contributes to equals, then it is not possible to write a perfectly correct equals method for the new class. instead, you should use composition instead of inheritance. 【程序编程相关:Mysql对文件操作的封装

hashcode and equals are closely related : 【推荐阅读:Hibernate 3新增XML关系持久

here is an implementation of equals for a data-centric class. it demonstrates how different types of fields are treated: 【扩展信息:使用Middlegen简化Hiberna

example


...   下一页
 ·java服务器端编程安全必读    »显示摘要«
    摘要: 概述和溢出  一、概述  编写安全的internet应用并不是一件轻而易举的事情:只要看看各个专业公告板就可以找到连续不断的安全漏洞报告。你如何保证自己的internet应用不象其他人的应用那样满是漏洞?你如何保证自己的名字不会出现在令人难堪的重大安全事故报道中?  如果你使用java servlet、javaserver pages(jsp)或者ejb,许多难以解决的问题都已经事先解决。当然,......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE