Let\'s say I have a class with a string field named \"myfield\", and use reflection to get the field, I\'ve found that Object.getClass().getDeclaredField(\"myfield\");
I don't mean to necro this thread but if you used any of the methods above inside a loop your performance will be awful. Create map beforehand
first take the item your search for to uppercase
item.getKey()
now create a map that has the uppercase version and the true fieldnames
Map fieldNames = Arrays.asList(clazz.getDeclaredFields()).stream().collect(Collectors.toMap(t -> t.getName().toUpperCase(), f->f.getName()));
now use that to grab the true fieldname
Field field = clazz.getDeclaredField(fieldNames.get(key));
I would say always create such a map, always consider performance when it comes to reflection.