
在Java中怎么把ArrayList<> 强行转换为float类型
publicclassa{staticArrayList<Side>map=null;staticArrayList<Integer>redAgg=null;static...
public class a{
static ArrayList<Side> map = null;
static ArrayList<Integer> redAgg = null;
static ArrayList<Integer> blueAgg = null;
static Side[] parents = null;
public static void main(String[] args){
// 初始化顶点集
int[] nodes ={ 0, 1, 3, 2, 4, 5,6 };
// 初始化有向权重图
map = new ArrayList<Side>();
map.add(new Side(0, 1, 10));
map.add(new Side(0, 3, 30));
我想把map.add(new Side(0, 1, 10));
中10的改为12.5 但是数据类型不支持,求高手解答!整个程序写不进来,可用QQ传给你!在线等答案!!! 展开
static ArrayList<Side> map = null;
static ArrayList<Integer> redAgg = null;
static ArrayList<Integer> blueAgg = null;
static Side[] parents = null;
public static void main(String[] args){
// 初始化顶点集
int[] nodes ={ 0, 1, 3, 2, 4, 5,6 };
// 初始化有向权重图
map = new ArrayList<Side>();
map.add(new Side(0, 1, 10));
map.add(new Side(0, 3, 30));
我想把map.add(new Side(0, 1, 10));
中10的改为12.5 但是数据类型不支持,求高手解答!整个程序写不进来,可用QQ传给你!在线等答案!!! 展开
展开全部
map = new ArrayList<Side>();
map中只能插入side类型的。而你的side方法不允许使用float。遇到这样的时候一般用泛型,来支持多种类型。强制类型转换会丢失精度。
map中只能插入side类型的。而你的side方法不允许使用float。遇到这样的时候一般用泛型,来支持多种类型。强制类型转换会丢失精度。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询