Java 泛型中的类型检查优点是如何体现的?

使用泛型代码要比非泛型代码更有优势,下面是 java 官方教程对泛型其中一个优点的介绍:

“Stronger type checks at compile time.
A Java compiler applies strong type checking to generic code and issues errors if the code violates type safety. Fixing compile-time errors is easier than fixing runtime errors, which can be difficult to find.”

我希望知道的是:

1、在使用泛型时能在编译时被检测出的问题,在未使用泛型时是怎样的情况?即怎样才会出现这类上文中最后一句提到的不是更容易解决的运行时错误?(希望以代码举例)

2、Java 如何提供这种编译时的强类型检查(第一句)。

如能解决,十分感谢!


米脂
浏览 568回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java