gpt4 book ai didi

java - 我的 friend 说我的方法没用,谁能解释一下为什么?

转载 作者:行者123 更新时间:2023-11-30 08:22:01 24 4
gpt4 key购买 nike

<分区>

我最近把我的源代码给了我的 friend ,这样他就可以查看它并告诉我是否有任何重大错误,例如内存泄漏、其他 Threads 中使用的非线程安全方法等。 ..

他看到了我的 HashmapWrapper 类,并告诉我它效率低下、无用且浪费空间。我真的很想知道为什么会这样,以及他所说的是否属实。

HashmapWrapper 类:

public class HashmapWrapper<K, V>
{
public HashMap<K, V> wrapped;

public HashMapWrapper()
{
this.wrapped = new HashMap<K, V>();
}

public HashmapWrapper<K, V> put(K key, V value)
{
this.wrapped.put(key, value);
return this.wrapped;
}

public HashMap<K, V> get()
{
return this.wrapped;
}
}

这是一个非常简单的类,它仅用于压缩我制作散列图的任何代码,然后将值赋给它们。

以下是我使用 HashmapWrapper 的一些示例:

settings.save(new HashmapWrapper<String, String>().put("volume", this.volume.getString()).put("res", this.screen.resolution.getString()).put("music", this.soundSystem.isMusicAllowed().getString()).put("font", this.font.getFontName()).get());

set(new HashmapWrapper<String, Integer>().put("coord.x", this.entity.xCoord).put("", this.entity.yCoord).get());

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