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


public class Box<T> {
    private T value;

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

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = 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();
        box1.setValue(box2.getValue());
        box2.setValue(temp);
    }
}




public class Main {
    public static void main(String[] args) {
        Box<String> box1 = new Box<>("Привет");
        Box<String> box2 = new Box<>("Java");

        box1.printType();

        NumberBox<Integer> numberBox = new NumberBox<>(10);
        System.out.println(numberBox.getDoubleValue());

        Utils.swapValues(box1, box2);

        System.out.println(box1.getValue());
        System.out.println(box2.getValue());
    }
}