equal

2024-07-23

equal(精选6篇)

equal 篇1

摘要:java编程中比较两个对象是否相同, 用Object的equals方法或“==”符号进行比较, equals方法和“==”是比较对象内存地址, 但在实际中, 仅以两个对象内存地址不同而判断它们不同是不够的, 需覆盖equals方法, 自定义判断标准, 本文将对覆盖equals方法遵循的原则和技巧进行分析和实现。

关键词:对象比较覆盖,equals

1 java中对象的比较

在java编程中, 提供了两个比较两个对象的方法, 一是用“==”运算符比较两个对象的内存地址。二是用Object的equals方法, 不覆盖直接使用也是对比对象内存地址。

我们编写一个人类和员工类, 员工类是人类的子类, 我们先不覆盖equals方法, 调用equals方法时, 比较对象地址。

(1) 编写Person类, 关键代码:

(2) 编写Employee类继承Person类, 关键代码:

(3) 以上两个类均没有覆盖equals方法, 调用使, 比较内存地址, 测试关键代码:

p2和p3是分别用new关键字创建出来的, 是不同地址的对象, 比较的结果是false。

2 覆盖java中的equals方法进行自定义比较

上面例子中, 有两个叫张三的对象, 调用没覆盖的equals方法时, 显示是不同对象, 假设我们业务上要求, 只要他们年龄、名字、工资相同, 认为两个对象是相同的, 即我们认为这两个张三, 是同一个人。

我们就覆盖equals方法, 自定义比较规则, 让其符合业务要求。

2.1 覆盖equals方法遵循的原则

java语言规范中有要求, 如果要覆盖equals方法, 那么覆盖后的方法应该具有下面几个的特点:

(1) 自反性:对于任何非空引用值x, x.equals (x) 都应返回true。

(2) 对称性:对于任何非空引用值x和y, 当且仅当y.equals (x) 返回true时, x.equals (y才应返回true。

(3) 传递性:对于任何非空引用值x、y和z, 如果x.equals (y) 返回true, 并且y.equals (z) 返回true, 那么x.equals (z) 应返回true。

(4) 一致性:对于任何非空引用值x和y, 多次调用x.equals (y) 始终返回true或false, 前提是对象上equals比较中所用的信息没被修改。对于任何非空引用值x, x.equals (null) 都返回false。

2.2 覆盖equals方法

(1) 覆盖person的equals方法, 关键代码:

上面的equals方法中用get Class实现, 比较的是同类型, 不在父子类对象间比较 (子类中没有比较的属性除外) , 所以这里的equals方法不能用于Person类对象和子类对象的比较。

(2) 覆盖Employee的equals方法, 关键代码:

(3) 运行测试代码。

运行结果

true

按照业务要求, 两个对象都具有相同的名字、年龄、工资, 所以是相同的。

3 小结

覆盖equals方法一定要遵循以上的原则, 如果需要比较子类和父类的对象, 还要进一步改进equals方法, 还建议覆盖hashcode方法, 比如Hash Set容器比较需要同时用到hashcode和equals方法。

参考文献

[1]林信良编著.Java JDK 7学习笔记[M].北京:清华大学出版社, 2012 (05) :01.

[2] (美) 霍斯特曼, 科内尔著.Java核心技术卷1[M].北京:机械工业出版社, 2014 (01) :01.

[3] (美) 埃克尔编著.Java编程思想 (第4版) [M].北京:机械工业出版社, 2007 (06) :01.

equal 篇2

1)显示参数命名为otherObject,稍后需要将它转换成另一个叫做other的变量。

2)检测this与otherObject是否引用同一个对象:

if(this == otherObject) return true;

这条语句只是一个优化。实际上这是一种经常使用的形式。

3)检测otherObject是否为null,如果为null,返回false。这项检测很必要。

if(otherObejct == null) return false;

比较this与otherObject是否为属于同一个类。如果equals的语义在每个子类中有所改变,就使用getClass检测:

if(getClass != otherObject.getClass()) return false;

如果所有的子类都拥有统一的语义,就使用instanceof检测:

if(!(otherObejct instanceof ClassName)) return false;

4)将otherObject转换为相应的类类型变量:

ClassName other = (ClassName)otherObject;

5)现在开始对所有需要比较的域进行比较了。使用==比较基本类型域,使用equals比较对象域。如果所有的域都匹配,就返回true,否则返回false。

return field == other.field&&field.equals(other.field)&&...;

如果在子类中重新定义equals,就要在其中包含调用super.equals(other)。

java的优势:

与传统程序不同,Sun 公司在推出 Java 之际就将其作为一种开放的技术。全球数以万计的 Java 开发公司被要求所设计的 Java软件必须相互兼容。“Java 语言靠群体的力量而非公司的力量”是Sun公司的口号之一,并获得了广大软件开发商的认同。这与微软公司所倡导的注重精英和封闭式的模式完全不同。

Sun 公司对 Java 编程语言的解释是:Java 编程语言是个简单、面向对象、分布式、解释性、健壮、安全与系统无关、可移植、高性能、多线程和静态的语言。

Java平台是基于 Java 语言的平台。这样的平台非常流行。因此微软公司推出了与之竞争的.NET平台以及模仿Java的C#语言。

equal 篇3

Ma said that under the Central Governments arrangement, several departments have drafted a plan for the reform based on extensive studies. The draft was then approved at the executive meeting of the State Council and by the Standing Committee of the Political Bureau of the Central Committee of the Communist Party of China (CPC). The reform comes from the constructive nature of the changes that will build a pension system for Party, government and public institutions with the same qualities as that for enterprises, and the reform will be carried out nationwide simultaneously with the reform of the salary system.

Under the current dual pension system, employees in government bodies and public institutions dont need to pay for their pensions, and the government supports fully them. However, employees in various types of enterprises have to pay 8 percent of their salary into a pension account. After retirement, urban employees usually get a pension equal to 40-60 percent of their final salary, but employees in government bodies and public institutions can get 80-90 percent of their final salary.

“The pension reform plan has been approved and is expected to be revealed soon, which means a significant step forward for pension reform,” said Lu Xuejing, Dean of the Department of Labor and Social Security of Capital University of Economics and Business.

Nie Riming, a researcher with the Shanghai Institute of Finance and Law, thinks the highlights of Mas report are the simultaneous implementation of pension system reform for both government employees and those in public institutions, as well as the establishment of a nationwide universal pension system.

At great cost

According to a report of the 21st Century Business Herald, a business newspaper based in Guangzhou, south Chinas Guangdong Province, there are 7 million government employees and 30 million public institution employees in China. Breaking the dual pension system means these 37 million people will be included into the pension system for urban employees.

A huge cost will be needed to unite the pension system for such a large number of people. In a paper written in 2013 by Lu Mingtao, a doctoral candidate from the Department of Economics of the Chinese Academy of Social Sciences (CASS), supposing the dual pension system was applicable to the retirees in and before 2010 and the new pension system is applicable to the retirees since 2011, the government has to pay 3.9 trillion yuan ($637.25 billion) for government employees and 5.2 trillion yuan ($849.67 billion) for employees of public institutions. In 2010, the countrys total fiscal revenue was 8.31 trillion yuan ($1.36 trillion).

Another estimate made by Nie shows that the government needs to pay 3.7 trillion yuan($604.58 billion) to employees of public institutions and 4.5 trillion yuan ($735.29 billion) to government employees.

How does China cover such high a cost? Nie offers two suggestions—either the government fully fills in the gap with fiscal revenue or the pension fund for urban employees will be used temporarily to make up for the gap. “These two options both face heavy financial pressure,” said Nie. “The governments fiscal revenue obviously cannot afford this sum of money.”

Some experts have thrown their support behind the decision to break the dual pension system. “In the short term, the reform will hurt some people, but in the long term, the reform will benefit all,” said Cheng Jie, an associate researcher with the Institute of Population and Labor Economics of the CASS. “By incorporating 37 million people into a large pool of hundreds of million people and relying on the resources of the whole society, the country will have a much stronger capability of sharing risks. Cheng also thinks the same as the cost of reforming state-owned enterprises, the financial gap for pension reform should also be mainly covered by government fiscal revenue.

Su Hainan, Vice President of the China Association for Labor Studies, thinks that since the reform will be carried out nationwide simultaneously, the Central Government will not make local governments to assume all the costs of pension reform. “If all costs were assumed by local governments, it would be highly likely that the reform wouldnt succeed in some areas,”Su said.

Zheng Bingwen, Director of the Center for International Social Security Studies of the CASS, said the pension reform this time will be carried out nationwide, and the transfer payment by the Central Government will cover the reform cost.

Regional gaps

In his report, Ma said China will promote the establishment of a national uniform pension program for urban employees based on the improvement of uniform management at provincial levels. Endowment insurance for non-employed urban and rural residents will be managed by provincial governments.

According to figures from the Financial and Economic Affairs Committee of the 12th National Peoples Congress, currently, among the 31 provinces, autonomous regions and municipalities, only six have established uniform pension programs for urban employees—Beijing, Tianjin, Shanghai, Tibet, Qinghai and Shaanxi.

Mas report said that because of differentiated financial affordability and different balances in the pension fund pools, pension standards differ remarkably among regions.

According to Nies estimation, in 2012, south Chinas Guangdong Province had the highest pension fund balance, standing at 387.96 billion yuan ($63.39 billion), while Tibet had the lowest, which was only 2.46 billion yuan ($401.96 million). In the same year, the average pension in Guangdong was 1,924 yuan ($314.38), and nine working people supported one retiree, while in northeast Chinas Heilongjiang Province, the average pension was 1,488 yuan ($243.14), and only one and a half working people supported a retiree, imposing a heavy burden on the working employees.

“To establish a national uniform program, provinces and municipalities that have high balances of pension funds will have to fill in the gaps for those with low balances, and well-developed provinces will certainly not be willing to do this,” said Nie. “It will be very difficult to establish a unified national program.”

equal 篇4

Jane Eyre is such a great novel that it plays an important role in the history of British literature.It also has been popular with readers all over the world since its publication in 1847.The author is a famous talented realistic woman novelist, who was born in a poor family at Thornton Yorkshire in 1816.Because of the spread of men’s oppression and the discrimination to women, Charlotte Bronte created Jane who had the same sufferings and experiences to express her desire for the equality between the sexes and the acquirement of freedom and independence.

1 Feminism in Jane Eyre

1.1 The definition of“feminism”

Feminism is a collection of social theories, political movements, and moral philosophies largely motivated by or concerned with the liberation of women.In simple terms, feminism is the belief that men and women should be equal in society, politician and economy, and it is also a movement organized around the belief that genders should not be the primary factor shaping a person’s social identity or political or economic rights.

1.2 The equality of social classes between Jane and Rochester

As we know, Jane is a girl who does not have a noble position, an illustrious background, and a beautiful appearance.But she never feels that she is inferior to others.Owing to Jane’s qualify of mind, courage, independence and strong personality, Rochester can not help falling in love with her.The strong thing is that it is Jane who declares her love to Rochester before he makes his sentiment clear to her.Jane expresses her feelings without hesitation.Evidently, Jane loves Rochester because he regards her as a human or even as an equal what is she strives for.

1.3 Jane’s opinion of equality between men and women

In“Jane Eyre”, everything shows that Jane struggles continually to achieve equality and to overcome oppression.In addition to class hierarchy, she must fight against those people that regard women are inferior to men.In the book, Mr.Brocklehurst, Edward Rochester and St John Rivers threaten her desire for equality and dignity, who want to keep Jane in a submissive position.And in front of them, she is unable to express her own ideas and feelings.We could see that women’s social status was so low that they were eager for equality and freedom in the 19th.Just because of this, Jane did not marry to Rochester until she made sure that they were equal with each other.Jane’s attitude to marriage showed her pursuit to happiness and reflected her expression towards equality of men and women.

2 Social and Cultural Backdrops of Jane Eyre

Jane Eyre was written in the early Victorian period when the conflict between labor and capital was so sharp.In this period the labor advocated democracy, freedom and equality.Jane lived in the mid-19thcentury which corresponded with the time of queen Victoria’s ruling.In this period a new literary trendcritical realism appeared and it flourished in the forties and in the early fifties.The critical realists described the chief traits of the English society with great artistic skill and much vividness and criticized the capitalist system from a democratic viewpoint.

In Jane Eyre, Charlotte Bronte chiefly resorts to the realistic approach, but her realistic points are mainly reflected by the romantic imagination.The author described Jane Eyre as a poor and plain girl which conformed to the characters of the female at that time.In all, Charlotte Bronte described the real phenomenon in the 19th through the love between Jane and Rochester.

3 The Influence of Jane Eyre on the Society Today

It is known to all that Jane Eyre is a female with ordinary appearance, even her own aunt feels disgusted with her.Despite her ordinariness, she was self-respect and independent.She expressed her standpoint directly and clearly that there should not be sexual discrimination and women should be treated as equally as men through the love with Rochester.Through the establishment of the image of Jane Eyre, a larger number of women began to realize their rights and freedom from then.At the same time, many women were inspired by the character of Jane.Women started to stand up and dared to struggle against the unequal treatment gradually.

4 Conclusion

From the above we can see that Jane is a good model for women in all aspects like her self-esteem, self-independence bravery and courage.Through the image of Jane, Charlotte Bronte expressed her wishes and hope of the equality between the sexes.At the same time, it drove the development of feminism and made the society so harmonious and peaceful between man and women today.

参考文献

[1]Blackburn, Ruth H.Charlotte Bronte Jane Eyre[M].New York:Simon&Schuster, 1974.

[2]Charlotte Bronte.Jane Eyre[M].Shanghai:Foreign Language Teaching and Research Press, 1996.

[3]Helena Wojtczak.Women of Victorian Sussex[M].London:Hastings Press, 2003.

[4]Margaret Lane.Introduction to Jane Eyre[M].London:Dent/Dutton, 1969.

[5]范文彬.论简爱的经久性魅力[J].外国文学研究.

[6]王雅静.论简爱中展现的人性力量[J].外国文学研究, 1989.

equal 篇5

I Also Have a Dream, one of Lin Das bestsellers, in some ways has some coincidence with Martin Luther Kings famous speech——I have a dream. It not only punningly indicates the gist of the book but also expresses Lins good wishes to racial equality.

Looked from the macroscopic angle, this book states the racial problems in America by telling many historical events and presenting Lins points of view. Actually, it epitomizes a process of achieving racial equality throughout the book in which the introspection of humanity, the impetus of social revolution, the foundation of the general public, the amendment and improvement of law and whole social progress are five steps. It is this process that pushes America forward.

First step is the introspection of humanity which is always mentioned in this book. All the thoughts and retrospection originate from The Declaration of Independence in which it says “we hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty, and the pursuit of Happiness”. People on the Mayflower reached the land in North America with the pursuit of freedom and equality and then this concept deeply rooted in each Americans mind. Americans know the importance of freedom and equality. Anyone does not have the right to deprive other peoples freedom and equality, even the blacks. Through Lin Das words, it is obvious that America is a strong nation which possesses introspective spirit that really plays an important role in American society. Lin Da acknowledges that “the dominant part of the national spirit has a strong function of auto-criticism and self-correction” (183). I always believe that only a nation envisages its shortcomings and faults can it gain introspection and make progress. When people were still in the colonial period, they were eager to form their own country to achieve the creed that all men are created equal; when they have established the United States, they opposed slavery; when they have finished the abolishment of slavery, they hoped to eliminate racial discrimination and abrogate racial separation. That is to say, their continuous introspection and the thinking of human nature became the foundation stone of social progress. Lin states that “the ‘majority rule we worship may become tyranny of the majority” (365-366). He also concludes that “ America is a country with a very short history but possesses the function of introspection. After all, introspection is the premise of progress” (403). However we can not say that Americans are incessantly holding such introspection in the whole history. They also made many mistakes and detours.

Second step is the impetus of social revolution which can be considered as the preliminary practice of the introspection of humanity. In the book, Lin Da interprets the cause and effect of the famous case——Amistad. Those black people on the Amistad have never imagined that they would be written into the annals of history and they could be returned to their homeland again some day. However, Amistad was destined to be a milestone in the history of America. With no exception, every relevant event will become a blasting fuse. Amistad is an example (Lin 97). Not only the case itself becomes the impetus of social revolution, but also the social power involved plays an important role. An “Amistad Committee” was established in New York and did a lot of helpful work. Members of the committee put ads in the newspaper to raise money for the blacks on which it said the rights of those blacks to pursue freedom and equality are according to natural law, international law and the call for freedom and humanity. With the help of those anti-slavery activists, the living conditions of those blacks improved a lot (Lin 109-110). What is more, activists also cared about the blacks mental state and tried their best to communicate with them though there existed an unconquerable barrier between them ——language.

The third step is the foundation of the general public,which is probably the most important one among the five steps. Without it, any reform, movement or campaign could not be smoothly implemented. The Emancipation Proclamation is considered by todays historians more of strategic concern than a moral declaration (Lin 230). Now that a law has come out, it should gain more support from the masses. Take the controversy between the North and the South as an example, after the Civil War, although national safety and integrity have been maintained and relevant policies and laws have issued, the concept of eliminating racial discrimination has not been accepted among people in some southern states. They refused it from deep inside. After regaining the rights of autonomy, the South used various methods to restrain the rise of the blacks social status as if resisting monsters. It is one of the reasons why several southern states such as Louisiana lag behind. As a consequence, It is no doubt that once the foundation of the masses is established, laws will be easily carried forward.

The fourth step is the amendment and improvement of law. The concept of law runs through the whole book, which reveals judicial fairness and legal supremacy. Amistads judgment is the best argument to explain why the blacks win the lawsuit in the end. When a judge is standing in the front of a threshold of historical progress, he feel confused because the current laws have conflicts and these conflicts may cause different judgment. In this case, his choice should accord with the direction of human progress and historical progress because it is based on the founding principle of natural law and the principle of humanity (147). Before reading this book, I could not totally understand why such little things like the abolition of slavery got stuck and brought little effect. In fact, such little change in America may cause great waves even disasters. Lin takes it as a “game rule”. To be more exact, everyone involved in a game must obey corresponding rules and any change of the rule should receive the approvals of all members. Compared with China, during the time of the Great Cultural Revolution, we did not obey the “game rule” to a great extent. Democracy and law were trampled thus caused great economic losses. Since the beginning of the reform and opening in 1978, China began to obey the “game rule” so politics have developed a lot and economic have gone back on track. “Game rule” is a universally applicable principle which is very useful in country governance.

The fifth step is whole social progress. In fact, in spite of the introspection of humanity, the impetus of social revolution or the foundation of the general public, the ultimate goal is to promote social progress institutionally and inwardly. What has really changed is peoples mind. After the Civil War, the blacks power accumulated and they became maturer inconspicuously. The sign of their maturity was that they were gradually aware of using the weapon of the law to pursue their attainable rights. Their rights are also a part of the countrys dream (Lin 276). Then, Martin Luther King Jr. , the famous black American civil rights leader was born in such circumstance. He organized 55,000 blacks to start a world-famous campaign —— Montgomery Bus Boycott which lasted 383 days and marked the beginning of the civil rights movement in the United States. It was a really magnificent feat for the blacks because it mostly attributed to the majority of the blacks rather than on Martin Luther King himself. Actually, Martin Luther Kings non-violent movement was a rational reflection and a performance of social progress. In that period, there were a lot of ambiguous anti-racists like Skeet devoted themselves in eliminating racial discrimination. Some of them even lost their lives. On June 21, 1964, two white undergraduates and a black undergraduate arrived at a small town in Mississippi to disseminate non-violent spirit. Several days later, they disappeared and were finally found died. Here, Lin supposes that the three undergraduates are utilized by enthusiastic anti-racists and then become the victims of social progress (Lin 350). He adds that he always suspects that some leaders of non-violent movement have known that this plan may bring a big impact and even danger. However, they insist on doing this out of the concern about political effect. Their goal is to appeal to equality and humanity but they fail to care about those whites volunteers in the process(Lin 349). Reviewing the whole event, the death of three undergraduates is really a tragedy Nevertheless, the progress of the history is based on tears of blood and a heavy price. But for these dedications, racial discrimination would not make a strong reaction among the people in the southern religion.

In the final chapter, Lin Da dreams about a harmonious world in which the whites and the blacks have a genuine coexistence without a little bit discrimination, abuse and separation. We can not ignore that the 21th century has witnessed national conflict, regional segregation and cultural antagonism. How to deal with the conflicts between person and person, district and district, nation and nation, different culture and custom may become the biggest problem in front of all human beings and no one can avoid (Lin 428). It is not only my dream but also everyones dream and we are eager to see it come true one day.

References:

[1]林达.我也有一个梦想:近距离看美国之三[M].北京:生活·读书·新知三联书店,2013.

equal 篇6

Speaking at an event held on the margins of the current session of the UN Commission on the Status of Women, Lakshmi Puri, Deputy Executive Director of UN Women, said the world had witnessed “numerous improvements” in women’s lives in fields such as employment and education since Beijing but equality was still elusive.

“No sector or country has met the standards laid out in Beijing, where gender equality is a reality,” she said. “While we should rejoice at the progress made when we look back and see where we are at present, we do have to convey a strong message … that we need to take every step, every measure, every law, every programme in order to push the pace and push the envelope on this issue.

“Otherwise, we are going to take almost another century to get to Planet 50:50 by 2030. This is absolutely not acceptable.”

She called for evaluation of the progress achieved but also of the gaps, with a focus on what the challenges have been and on how to get to Planet 50:50 by 2030.

The Beijing Platform for Action, she noted, mandated the full participation of women in the public, private and governmental realms.

“It also affirms that the equal and active participation of women is fundamental for the achievement of equality, development and peace,” she said, going on to note the demands it made of the UN system as well.

She said responsibility for implementing the Platform lay at the highest level and she pointed to the proven importance of the role of senior leaders in catalysing and bringing about change, highlighting Secretary-General Ban Ki-moon as a good example of a leader who had stood behind positive change.

Even within the UN system, the situation of women faced significant challenges and had not achieved the aims of the Beijing Platform, noted Ms. Puri.

【equal】推荐阅读:

上一篇:未来计算的三大趋势下一篇:新农村改革

本站热搜

    相关推荐