There is no guarantee that you will get the same objects from different calls and the chances are that you won't. One thing you can do is check the source code for the Class class.
In my installation of jdk1.8.0_131 has the following as the code for getFields()
public Field[] getFields() throws SecurityException {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
return copyFields(privateGetPublicFields(null));
}
Now you can follow that further, but I'm thinking that this makes a copy of some internal data.
This doesn't mean that the values wont work as keys in a HashMap however, because the HashMap will use the .equals() and .hashCode() methods to determine if two keys are the same, and not the equals operator '=='.
So here is some clunky code to investigate this:
public static void main(String... none) throws Exception {
Field[] fields1 = Point.class.getFields();
Field[] fields2 = Point.class.getFields();
for (int i = 0; i < fields1.length; ++i) {
compare(fields1[i], fields2[i]);
}
}
static void compare(Field field1, Field field2) {
System.out.format("Field %s\n", field1.getName());
System.out.format("field1 == field2 -> %s\n", field1 == field2);
System.out.format("field1.equals(field2) -> %s\n", field1.equals(field2));
System.out.format("field1.hashCode() == field2.hashCode() -> %s\n", field1.hashCode() == field2.hashCode());
System.out.println();
}
Which for me has the output:
Field x
field1 == field2 -> false
field1.equals(field2) -> true
field1.hashCode()==field2.hashCode() -> true
Field y
field1 == field2 -> false
field1.equals(field2) -> true
field1.hashCode() == field2.hashCode() -> true
So it looks like you may be ok to use the Field instances as keys. Furthermore if you look at the documentation for .equals() on Field it reads:
/**
* Compares this {@code Field} against the specified object. Returns
* true if the objects are the same. Two {@code Field} objects are the same if
* they were declared by the same class and have the same name
* and type.
*/
There is similar documentation for .hashCode() so you'll probably be ok using the field as a key.