Загрузка данных


public class Box<T> {
    private T value;

    public Box(T value) {
        this.value = value;
    }

    public T getValue() {
        return value;
    }

    public void printType() {
        System.out.println("В коробке лежит объект типа: " + value.getClass().getSimpleName());
    }
}



public class NumberBox<T extends Number> {
    private T value;

    public NumberBox(T value) {
        this.value = value;
    }

    public double getDoubleValue() {
        return value.doubleValue();
    }
}



public class Utils {
    public static <T> void swapValues(Box<T> box1, Box<T> box2) {
        T temp = box1.getValue();

        try {
            java.lang.reflect.Field field = Box.class.getDeclaredField("value");
            field.setAccessible(true);
            field.set(box1, box2.getValue());
            field.set(box2, temp);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}