MayiktList.java 接口
- package com.collection.Demo06;
-
- public interface MayiktList
{ - void add(E e);
-
- E get(int index);
- }
MayiktArrayList.java 实现类
- package com.collection.Demo06;
-
- public class MayiktArrayList
implements MayiktList { -
- @Override
- public void add(E e) {
- System.out.println("新增成功");
- }
-
- @Override
- public E get(int index) {
- System.out.println("查询成功");
- E e = null;
- return e;
-
- }
- }
Test01.java
- package com.collection.Demo06;
-
- /**
- * 实现ArrayList集合泛型
- */
- public class Test01 {
- public static void main(String[] args) {
- MayiktList
stringMayiktArrayList = new MayiktArrayList<>(); - stringMayiktArrayList.add("");//输入String类型,返回void
- stringMayiktArrayList.get(1);//输入int类型,返回String
- }
- }
下一篇文章:泛型通配符