Code example for Field

Methods: isAccessible, setAccessible

0
	 */ 
	public FieldComparator(Class<T> clazz, String fieldName)  {
		try { 
			compareField = clazz.getDeclaredField(fieldName);
			// Make sure we can access it even if it is private 
			if (!compareField.isAccessible()) {
				compareField.setAccessible(true);
			} 
		} catch (Exception e) {
			// convert to a runtime 
			throw new RuntimeException(e);
		} 
	} 
 
	@Override 
	public int compare(T o1, T o2) {
		if (o1 == null) {
			if (o2 == null)
				return 0; 
			else 
				return -1;