2 changed files with 30 additions and 0 deletions
@ -0,0 +1,19 @@ |
|||||
|
一、Java泛型擦除后如何通过反射获取泛型类型? |
||||
|
1、通过父类/超类类型参数获取 |
||||
|
2、获取方法参数/返回值的泛型类型 |
||||
|
3、获取字段的泛型类型 |
||||
|
二、AI审查 |
||||
|
|
||||
|
✅ 优点 |
||||
|
泛型设计正确 - Cache<K,V> 泛型声明规范 |
||||
|
|
||||
|
封装合理 - storage 字段为 private,符合封装原则 |
||||
|
|
||||
|
委托模式 - 方法直接委托给 HashMap,简单高效 |
||||
|
|
||||
|
构造函数初始化 - 正确创建了 HashMap 实例 |
||||
|
|
||||
|
代码基础不错,功能完整,主要是缺少一些企业级实践(线程安全、Optional 使用等)。 |
||||
|
|
||||
|
三、为什么Java泛型不支持基本类型? |
||||
|
因为Java泛型是通过类型擦除实现的,运行时所有泛型类型都会被替换为Object,而基本类型不是Object的子类。 |
||||
@ -0,0 +1,11 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<module type="JAVA_MODULE" version="4"> |
||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true"> |
||||
|
<exclude-output /> |
||||
|
<content url="file://$MODULE_DIR$"> |
||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> |
||||
|
</content> |
||||
|
<orderEntry type="inheritedJdk" /> |
||||
|
<orderEntry type="sourceFolder" forTests="false" /> |
||||
|
</component> |
||||
|
</module> |
||||
Loading…
Reference in new issue