Why is there no guava Objects.equal (Object, Object) for primitive types?

Why not Objects.equal, taking each primitive type as an argument?

I know that you can insert a value through #valueOfor allow each primitive to be auto-boxed, but don't you lose performance? This is what I once thought about.

Imagine I have something like

public class Foo {
    private final int integerValue;
    private final boolean booleanValue;
    private final Bar bar;

    public Foo(int integerValue, boolean booleanValue, Bar bar) {
        this.integerValue = integerValue;
        this.booleanValue = booleanValue;
        this.bar = bar;
    }

    @SuppressWarnings("boxing")
    @Override
    public boolean equals(Object object) {
        if (object instanceof Foo) {
            Foo that = (Foo) object;

            return Objects.equal(this.integerValue, that.integerValue)
                     && Objects.equal(this.booleanValue, that.booleanValue)
                     && Objects.equal(this.bar, that.bar);
        }
        return false;
    }

    // hashCode implementation using guava also.
}

equals? , ( ) . == , "" equals, . , guava lib Objects.equal . - ?

MoreObjects.toStringHelper ( ), , , Objects#equal. , JB Nizet, equals , int Integer, .

Guava

+5
2

== , "" equals, .

API Guava - , API, , . , .

+6

, #valueOf , , ?

, == , if_icmpeq . , Objects.equal, , , , , , , .

, Objects.equal , , , .

+2

All Articles