title: How to use Java-Reflection to set the value of type scala.Enumeration
body: <p>I have a complicated reflection-based Java-Application which I now translated partly into scala. Howerver, the reflection-based part is still in Java ...</p>
  
  <p>Now I have a scala enumeration type, for instance:</p>
  
  <pre><code>object DayType extends Enumeration {
    type DayType = Value
  
    val Monday = Value("Monday")
    val Tuesday = Value("Tuesday")
    ...
  }
  </code></pre>
  
  <p>Now I use Java Reflection in a following way:</p>
  
  <pre><code>public static void setFieldValue(Object o, String fieldName, String value) {
  
    Field field;
    try {
      field = o.getClass().getField(fieldName);
    } catch (NoSuchFieldException e) {
      // in Scala EVERY field is private.
      field = o.getClass().getDeclaredField(fieldName);
      field.setAccessible(true);
    }
  
    Class type = field.getType();
    if (type == Float.TYPE) {
      field.setFloat(o, Float.parseFloat(value));
    } 
    if (type == Integer.TYPE) {
      field.setInt(o, Integer.parseInt(value));
    }
  
    ...
  
    if (type.getName().equals("scala.Enumeration$Value")) {
      System.out.println("fieldname: " + field.getName());
      System.out.println("fieldtype: " + field.getType());
      try {
        field.set(o, ???);
      } catch (Exception e) {
        System.out.println(e.getMessage());
      }
  
    ...
  </code></pre>
  
  <p>At least the type recognition works correctly, however, two questions remain:
   1. Is there a way to recognize the type without going via the name? if (type == Enumeration.class) does not work, if (type == Enumeration) also not (the   second solution does not even compile)
   2. How to set the value? How to replace "???" Simply doing field.set(o, value) leads to a "Can not set scala.Enumeration$Value field diva.module.AdaptationFloodingNew.adaptMode to java.lang.String" exception (which is reasonable).</p>