Bug 261489 - [hashcode/equals] Cannot generate equals and hashcode for a class without instance members
Summary: [hashcode/equals] Cannot generate equals and hashcode for a class without ins...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-19 06:55 EST by Ketan Padegaonkar CLA
Modified: 2023-05-10 13:11 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ketan Padegaonkar CLA 2009-01-19 06:55:07 EST
There is no reason why a class without instance variables cannot have an equals and hashcode.

Here's what my class looks like:

package com.thoughtworks.twist.core.resolver;
public class BooleanResolver {
    public boolean canResolve(String type) {
        return "true".equalsIgnoreCase(type) || "false".equalsIgnoreCase(type);
    }
}

I'd expect the hashcode and equals generator to generate the following for me instead of telling me that eclipse cannot create the methods because my class does not have fields in this class.

    // can be shortened to "return 31" instead
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result;
        return result;
    }

    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        return true;
    }
Comment 1 Eclipse Genie CLA 2019-04-27 09:54:53 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Dani Megert CLA 2019-04-28 10:35:16 EDT
Still an issue in 4.12 M1.
Comment 3 Eclipse Genie CLA 2021-04-20 16:33:30 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Eclipse Genie CLA 2023-05-10 13:11:47 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.