Пример #1
0
  public static IValue autoBox(IValue value, IType valueType, IType targetType) {
    if (!targetType.isSuperTypeOf(valueType)) {
      return null;
    }

    boolean primitive = valueType.isPrimitive();
    if (primitive != targetType.isPrimitive()) {
      // Box Primitive -> Object
      if (primitive) {
        return new BoxedValue(value, valueType.getBoxMethod());
      }
      // Unbox Object -> Primitive
      return new BoxedValue(value, targetType.getUnboxMethod());
    }
    return value;
  }