static void smartSet(Field f, O o, O value) throws Exception { f.setAccessible(true); // take care of common case (long to int) if (f.getType() == int.class && value instanceof Long) value = ((Long) value).intValue(); try { f.set(o, value); } catch (Exception e) { if (f.getType().getName().equals("main$Concept$Ref")) f.set(o, nuObject("main$Concept$Ref", o, value)); else if (o.getClass().getName().equals("main$Concept$Ref")) f.set(o, call(o, "get")); else throw e; } }