克隆HashSet时如何避免未经检查的转换警告? [英] How to avoid unchecked cast warning when cloning a HashSet?

查看:54
本文介绍了克隆HashSet时如何避免未经检查的转换警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个称为myHash的点的HashSet的浅表副本。到目前为止,我有以下内容:

I'm trying to make a shallow copy of a HashSet of Points called myHash. As of now, I have the following:

HashSet<Point> myNewHash = (HashSet<Point>) myHash.clone();

这段代码给了我未经检查的强制转换警告。有更好的方法吗?

This code gives me an unchecked cast warning however. Is there a better way to do this?

推荐答案

您可以尝试以下方法:

HashSet<Point> myNewHash = new HashSet<Point>(myHash);

这篇关于克隆HashSet时如何避免未经检查的转换警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆