【Java】Generics in Java

2023-07-21 14:14:29 浏览数 (1)

原文

Generics in Java. It’s all about type safety | by Salitha Chathuranga | Medium

引言

It’s all about type safety。

所有内容都是关于线程安全。

Hi all!!!

I thought of writing a widely used but less discussed topic in Java. That is Generics! We use it, but majority of the developers don’t know about it as I have experienced.

本次编写的有关内容是讨论较少主题,“泛型”,实际上我们经常使用(实际上天天都在用),但是大部分人并不了解。

Let me clear this…have you ever used List or ArrayList in Java? Most probably, answer should be YES. Right? Without collections, we can’t even think of an easy way of handling data. So, do you remember how we define an ArrayList?

让我澄清一下......您在Java中使用过List或ArrayList吗?答案很可能是 "是"。对不对?如果没有集合,我们甚至无法想象处理数据的简单方法。那么,你还记得我们是如何定义ArrayList的吗?

代码语言:java复制
List<Integer> numbers = new ArrayList<>(); // with Generics

This is the way we declare it. So, we have used generics.

0 人点赞