gpt4 book ai didi

java - 使用保存类保存值并在调用时打印先前保存的值

转载 作者:行者123 更新时间:2023-11-29 05:32:53 25 4
gpt4 key购买 nike

<分区>

我正在为期末考试学习,但我对如何解决这个问题感到困惑。

Write a generic class named Saver. It should have one method named save. This method should store the value that is passed and return the previous value For example, this class should support the following behavior:

Saver<Integer> saver1 = new Saver(13);
System.out.println(saver2.save(42)); // prints 13
System.out.println(saver2.save(-999)); // prints 42
System.out.println(saver2.save(2013)); // prints -999

Saver<String> saver2 = new Saver("foo");
System.out.println(saver2.save("bar")); // prints foo
System.out.println(saver2.save("why")); // prints bar
System.out.println(saver2.save("yar")); // prints why

我不需要代码,我只想知道如何完成这个任务?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com