File tree Expand file tree Collapse file tree
src/main/java/com/cpucode/generics Expand file tree Collapse file tree Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+
2+ # [ 泛型] ( ../README.md )
3+
4+ ## 文件目录
5+
6+ --------------------
7+
8+ ## [ 泛型] ( src/main/java/com/cpucode/generics )
9+
10+ - [x] [ Generic1__ 错误类型转换异常] ( src/main/java/com/cpucode/generics/Generic1.java )
11+ - [x] [ Generic2__ 泛型的引入] ( src/main/java/com/cpucode/generics/Generic2.java )
12+ - [x] [ Generic3__ 定义和使用含有泛型的类] ( src/main/java/com/cpucode/generics/Generic3.java )
13+ - [x] [ Generic4__ 泛型的方法] ( src/main/java/com/cpucode/generics/Generic4.java )
14+ - [x] [ Generic5__ 泛型的接口] ( src/main/java/com/cpucode/generics/Generic5.java )
15+ - [x] [ Generic6__ 泛型通配符] ( src/main/java/com/cpucode/generics/Generic6.java )
16+ - [x] [ Generic7__ 受限泛型] ( src/main/java/com/cpucode/generics/Generic7.java )
17+
18+ - [ 返回目录] ( #文件目录 )
19+
20+ -------------
21+
22+ - [ 返回顶层] ( ../README.md )
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule=" true" type =" JAVA_MODULE" version =" 4" >
3+ <component name =" NewModuleRootManager" LANGUAGE_LEVEL =" JDK_1_8" >
4+ <output url =" file://$MODULE_DIR$/target/classes" />
5+ <output-test url =" file://$MODULE_DIR$/target/test-classes" />
6+ <content url =" file://$MODULE_DIR$" >
7+ <sourceFolder url =" file://$MODULE_DIR$/src/main/java" isTestSource =" false" />
8+ <sourceFolder url =" file://$MODULE_DIR$/src/main/resources" type =" java-resource" />
9+ <sourceFolder url =" file://$MODULE_DIR$/src/test/java" isTestSource =" true" />
10+ <excludeFolder url =" file://$MODULE_DIR$/target" />
11+ </content >
12+ <orderEntry type =" inheritedJdk" />
13+ <orderEntry type =" sourceFolder" forTests =" false" />
14+ </component >
15+ </module >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5+ <modelVersion >4.0.0</modelVersion >
6+
7+ <groupId >com.cpucode</groupId >
8+ <artifactId >generics</artifactId >
9+ <version >1.0-SNAPSHOT</version >
10+
11+ <build >
12+ <plugins >
13+ <!-- java编译插件 -->
14+ <plugin >
15+ <groupId >org.apache.maven.plugins</groupId >
16+ <artifactId >maven-compiler-plugin</artifactId >
17+ <version >3.2</version >
18+ <configuration >
19+ <source >1.8</source >
20+ <target >1.8</target >
21+ <encoding >UTF-8</encoding >
22+ </configuration >
23+ </plugin >
24+ </plugins >
25+ </build >
26+
27+ </project >
Original file line number Diff line number Diff line change 1+
2+ package com .cpucode .generics ;
3+
4+ import java .util .ArrayList ;
5+ import java .util .Collection ;
6+ import java .util .Iterator ;
7+
8+ public class Generic1 {
9+ public static void main (String [] args ) {
10+ Collection coll = new ArrayList ();
11+
12+ coll .add ("cpucode" );
13+ coll .add ("cpu" );
14+ //由于集合没有做任何限定,任何类型都可以给其中存放
15+ coll .add (5 );
16+
17+ Iterator it = coll .iterator ();
18+
19+ while (it .hasNext ()){
20+ //需要打印每个字符串的长度,就要把迭代出来的对象转成String类型
21+ String str = (String ) it .next ();
22+ System .out .println (str .length ());
23+ }
24+ }
25+ }
26+
27+ /*
28+ 7
29+ 3
30+ Exception in thread "main" java.lang.ClassCastException: c
31+ */
Original file line number Diff line number Diff line change 99 * @CSDN: [https://blog.csdn.net/qq_44226094](https://blog.csdn.net/qq_44226094)
1010 * @Gitbook: [https://923992029.gitbook.io/cpucode/](https://923992029.gitbook.io/cpucode/)
1111 */
12- package Generic ;
12+ package com . cpucode . generics ;
1313
1414import java .util .ArrayList ;
1515import java .util .Collection ;
Original file line number Diff line number Diff line change 1- /*
2- * @由于个人水平有限, 难免有些错误, 还请指点:
3- * @Author: cpu_code
4- * @Date: 2020-09-16 17:56:00
5- * @LastEditTime: 2020-09-16 18:01:40
6- * @FilePath: \java\Generic\Generic3.java
7- * @Gitee: [https://gitee.com/cpu_code](https://gitee.com/cpu_code)
8- * @Github: [https://github.com/CPU-Code](https://github.com/CPU-Code)
9- * @CSDN: [https://blog.csdn.net/qq_44226094](https://blog.csdn.net/qq_44226094)
10- * @Gitbook: [https://923992029.gitbook.io/cpucode/](https://923992029.gitbook.io/cpucode/)
11- */
12- package Generic ;
1+ package com .cpucode .generics ;
132
143public class Generic3 {
154 public static void main (String [] args ) {
@@ -42,9 +31,4 @@ public void setMvp(MVP mvp) {
4231 public MVP getMvp () {
4332 return mvp ;
4433 }
45- }
46-
47- /*
48- cpucode
49- 100
50- */
34+ }
You can’t perform that action at this time.
0 commit comments