일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- aggs
- License
- springboot
- license delete
- API
- plugin
- Test
- ELASTIC
- token filter test
- Kafka
- MySQL
- matplotlib
- analyzer test
- Python
- Elasticsearch
- Java
- sort
- 차트
- flask
- docker
- high level client
- aggregation
- Mac
- 파이썬
- zip 파일 암호화
- 900gle
- zip 암호화
- query
- TensorFlow
- licence delete curl
Archives
- Today
- Total
개발잡부
generic 본문
반응형
Human.java
package com.test.doo.entities;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class Human<T, M> {
protected T name;
protected M age;
}
Boy.java
package com.test.doo.entities;
public class Boy<T, M> extends Human{
}
Girl.java
package com.test.doo.entities;
public class Girl<T, M> extends Human {
}
Main.Java
package com.test.doo.entities;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
Girl<String, Integer> girl = new Girl();
girl.setName("sh");
girl.setAge(45);
Boy<String, Integer> boy = new Boy();
boy.setName("dh");
boy.setAge(38);
Cat cat = new Cat();
cat.setSpecies("kor");
cat.setAge(2);
List<Human> humans = new ArrayList<>();
Utiles.<Human>getMember(humans, girl);
Utiles.<Human>getMember(humans, boy);
// Utiles.getMember(humans, cat);
humans.stream().forEach(x -> {
System.out.println(x.getName());
}
);
}
}
Utiles.java
package com.test.doo.entities;
import java.util.List;
public class Utiles {
public static <T extends Human> List<? extends Human> getMember(List<T> list , T t){
list.add(t);
return list;
}
}
반응형
'JAVA' 카테고리의 다른 글
[java] 10진수 를 2진수, 8진수, 16진수로 변환하기 (0) | 2023.05.15 |
---|---|
[java] Spark java tutorial (0) | 2022.06.05 |
Error querying database (0) | 2022.04.25 |
Table 'shop.hibernate_sequence' doesn't exist (0) | 2022.04.16 |
Comments