是ArrayList是类型安全或强类型? [英] Is Arraylist is typesafe or strongly typed?

查看:134
本文介绍了是ArrayList是类型安全或强类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道到底的强类型和安全型的区别是什么!

I don't know what exactly the difference between "Strongly typed" and "Type safety" is!

请您在一个简单的语言阐明这一点?

Could you please clarify this in a simple language?

假设我们使用ArrayList的,但我无法断定它是类型安全或强类型。或者我们可以用它作为两个?

Suppose we are using Arraylist, but I am unable to conclude it is typesafe or strongly typed. or can we use it as both.?

推荐答案

这是的ArrayList 不是类型安全的。这意味着的是,的ArrayList 可分配任何类型的值:

An ArrayList is not typesafe. What this means is that ArrayList can be assigned a value of any type:

ArrayList myList = new ArrayList();
myList.Add("this is a string");
myList.Add(19); //Notice that this is an int, but it doesn't throw an error!

这是一个问题,因为当你去使用列表,你不知道,在列表中的类型。其引发的错误的几率非常高。

This is an issue because when you go to use the list, you don't know the types that are in the list. The chances of having an error thrown are very high.

的ArrayList 避免使用!使用一个通用的列表,而不是如列表< T>

Avoid using ArrayLists! Use a generic list instead, such as List<T>

这篇关于是ArrayList是类型安全或强类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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