@Override
  public Object evaluate(DeferredObject[] arguments) throws HiveException {
    Object targetObject = targetOI.getPrimitiveJavaObject(arguments[0].get());
    if (targetObject == null) {
      return null;
    }
    Object result = null;
    try {
      result = method.invoke(targetObject, setupParameters(arguments, 2));
    } catch (InvocationTargetException e) {
      throw new HiveException(e.getCause());
    } catch (Exception e) {
      throw new HiveException(e);
    }
    if (result == null) {
      return null;
    }
    switch (returnOI.getPrimitiveCategory()) {
      case VOID:
        return null;
      case BOOLEAN:
        ((BooleanWritable)returnObj).set((Boolean)result);
        return returnObj;
      case BYTE:
        ((ByteWritable)returnObj).set((Byte)result);
        return returnObj;
      case SHORT:
        ((ShortWritable)returnObj).set((Short)result);
        return returnObj;
      case INT:
        ((IntWritable)returnObj).set((Integer)result);
        return returnObj;
      case LONG:
        ((LongWritable)returnObj).set((Long)result);
        return returnObj;
      case FLOAT:
        ((FloatWritable)returnObj).set((Float)result);
        return returnObj;
      case DOUBLE:
        ((DoubleWritable)returnObj).set((Double)result);
        return returnObj;
      case STRING:
        ((Text)returnObj).set((String)result);
        return returnObj;
      case TIMESTAMP:
        ((TimestampWritableV2)returnObj).set((Timestamp)result);
        return returnObj;
      case BINARY:
        ((BytesWritable)returnObj).set((byte[])result, 0, ((byte[]) result).length);
        return returnObj;
      case DECIMAL:
        ((HiveDecimalWritable)returnObj).set((HiveDecimal)result);
        return returnObj;
    }
    throw new HiveException("Invalid type " + returnOI.getPrimitiveCategory());
  }
A simple generic udf to call java functions via reflection.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFReflect2.java