Built on Sin
Built on Sin

Reputation: 351

Java getClass().equals() Comparison

Why does this comparison using .getClass().equals() not work?

System.out.println("worldX: " + worldX.get(j).getClass());
System.out.println("-block: " + block.getClass());
System.out.println("Comparison: " + worldX.get(j).
        getClass().equals(bug.getClass()));

It prints out the following:

worldX: class aWorld.ABlock
-block: class aWorld.ABlock
Comparison: false

Edit: Comparing different classes than those which I meant to compare.

Upvotes: 0

Views: 6061

Answers (1)

NPE
NPE

Reputation: 500663

You are printing the classes of worldX and block, but then comparing the former to bug (whatever that is).

If they are the same class and getClass().equals() returns false, one possibility is that there are multiple class loaders at play.

Upvotes: 3

Related Questions