Skip to content

Commit 7fdef13

Browse files
committed
update
1 parent 85f4e75 commit 7fdef13

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

.idea/workspace.xml

Lines changed: 9 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/java/Generic/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
- V – It represents values.
99
- N – It represents numbers.
1010

11+
1112
## Generics terms:
1213
![generics1](https://user-images.githubusercontent.com/122768076/234642733-85324b1a-a674-4f18-b878-9c359fe02cc4.jpg)
1314

1415

15-
## 1. Lớp generic (Generic class):
16+
## 1. Lớp generic (Generic class):
1617
Lớp generic là một lớp có thể được khai báo với một hoặc nhiều tham số generic. Tham số generic có thể được sử dụng để xác định kiểu đối tượng mà lớp sẽ hoạt động trên.
1718

1819
Syntax:

src/java/Generic/main.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package src.java.Generic;
2+
3+
class MyClass {}
4+
class MySubClass extends MyClass {}
5+
6+
public class main {
7+
public <T extends MyClass> void printMyClass(T t) {
8+
System.out.println(t.getClass().getName()); // Reflection
9+
}
10+
11+
public static void main(String[] args) {
12+
MyClass myObj = new MyClass();
13+
MySubClass mySubObj = new MySubClass();
14+
15+
main obj = new main();
16+
obj.printMyClass(myObj);
17+
obj.printMyClass(mySubObj);
18+
}
19+
}

0 commit comments

Comments
 (0)