protected Field getField(Object obj, String fieldname)
	{
		Class<?> type = obj.getClass();

		// Creates the fields cache
		if (fields == null)
		{
			fields = new HashMap<Class, Map<String, Field>>();
		}

		// Creates the fields cache entry for the given type
		Map<String, Field> map = fields.get(type);

		if (map == null)
		{
			map = new HashMap<String, Field>();
			fields.put(type, map);
		}

		// Tries to get cached field
		Field field = map.get(fieldname);

		if (field != null)
		{
			return field;
		}

		while (type != null)
		{
			try
			{
				field = type.getDeclaredField(fieldname);

				if (field != null)
				{
					// Adds field to fields cache
					map.put(fieldname, field);

					return field;
				}
			}
			catch (Exception e)
			{
				// ignore
			}

			type = type.getSuperclass();
		}

		return null;
	}