官术网_书友最值得收藏!

How it works...

The first class we created, StackInt, is a stack that can work only with the Int type. It's good if you are going to use it with Int type only. However, a famous data structure like it can be used with different types, such as String or Double. It's not possible to create different stack class for each type, and here comes the magic of generics; instead we created another class called Stack marked with <T> to say it's going to deal with the generic type T, which can be Int, String, Double, and so on. Then, we create two stack instances, stackOfStrings and stackOfInt, and both share the same code as their class is built with generics.

主站蜘蛛池模板: 清河县| 青州市| 高清| 朝阳区| 峡江县| 寻乌县| 天津市| 望奎县| 昭觉县| 拉萨市| 那曲县| 岳池县| 大悟县| 南华县| 巴楚县| 珠海市| 磐安县| 穆棱市| 武清区| 澄城县| 酒泉市| 咸阳市| 涪陵区| 保靖县| 福建省| 读书| 桃源县| 四平市| 崇信县| 麻江县| 元江| 蓬溪县| 卢龙县| 佳木斯市| 澄迈县| 萝北县| 梅州市| 泸溪县| 新干县| 贵溪市| 于都县|