Java Reflection Java Java API
Class:
java.lang.reflect.Field
Method:
public boolean equals(Object obj)
Field class overrides Object.equals() method and compares this Field against the specified object. It returns true if the two Field objects are the same. The two objects will only be the same if they were declared by the same class and have the same name and type.
Examples
package com.logicbig.example.field;
import java.lang.reflect.Field;
public class EqualsExample { private int anInt; private int otherInt;
public static void main(String... args) throws NoSuchFieldException { Field field1 = EqualsExample.class.getDeclaredField("anInt"); Field field2 = EqualsExample.class.getDeclaredField("otherInt"); Field field3 = EqualsExample.class.getDeclaredField("anInt");
boolean equals = field1.equals(field2); System.out.println(equals);
equals = field1.equals(field3); System.out.println(equals);
equals = field2.equals(field3); System.out.println(equals); } }
Outputfalse true false
|