Comparable泛型踩坑
发表于|更新于
|浏览量:
善疑人者,人亦疑之;善防人者,人亦防之。——刘基
之前写的Comparable解决泛型限定问题
遇到了这种情况:

这是因为LocalDate没有实现Comparable<LocalDate>
而是由其实现的接口ChronoLocalDate去继承的Comparable<ChronoLocalDate>
并且LocalDate去实现的Serializable,而不是ChronoLocalDate

我们这里直接用的T extends Comparable<T>,此处传了LocalDate就是extends Comparable<LocalDate>
和实现Serializable的不是同一层级,所以我们需要指定为Comparable<? super T>,这个意思就是说允许Comparable里的类型是它的父类或者接口,具体super和extends区别可以看泛型的super和extends

改成Comparable<? super T>后,编译通过
相关推荐
2021-01-26
isSynthetic
巧诈不如拙诚。——韩非子 isSynthetic这个函数,在Class类中存在,在Field类中存在,一搜,发现还挺多地方都有这个函数 这个函数我们点进去看源码和注释 1234567891011/** * Returns {@code true} if this class is a synthetic class; * returns {@code false} otherwise. * @return {@code true} if and only if this class is a synthetic class as * defined by the Java Language Specification. * @jls 13.1 The Form of a Binary * @since 1.5 */public boolean isSynthetic() { return (getModifiers() & SYNTHETIC) != 0;} 12...
2024-03-15
stream-query多数据库进行CI测试
把时间花费在阅读他人的著述吧,你可借他人辛苦的东西,轻易改善自己。——苏格拉底 最近针对stream-query,使用github action | 阿超 主要是针对h2、mysql、postgresql各跑一遍对应的脚本和单元测试 配置脚本为: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182name: E2E Testson: push: branches: - e2e pull_request: branches: - e2ejobs: test: runs-on: ubuntu-latest services: mysql: image: mysql:8.0 env: MYSQL_ROOT_PASSWORD...
2022-08-16
全局响应返回处理
我喜欢我的懦弱,痛苦和难堪也喜欢。喜欢夏天的光照,风的气息,蝉的鸣叫,喜欢这些,喜欢得不得了。——《寻羊冒险记》 上代码: 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import io.github.vampireachao.stream.core.optional.Opp;import org.springframework.core.MethodParameter;import org.springframework.http.MediaType;import org.springframework.http.converter.HttpMessageConverter;import org.springframework.http.server.ServerHttpRequest;import org.springframework.http.server.ServerHttpResponse;import org.springframewor...
2022-02-14
hutool中@Alias
何必向不值得的人证明什么,生活得更好,乃是为你自己——忽而今夏 我们可以使用hutool中的@Alias注解去给bean取别名,例如: 1234567@Datapublic static class BeanWithAlias { @Alias("name") private String value1; @Alias("age") private Integer value2;} 然后别名不仅能在BeanUtil.copyProperties中使用,还可以在JSONUtil中使用: 123456789101112131415final BeanWithAlias beanWithAlias = new BeanWithAlias();beanWithAlias.setValue1("张三");beanWithAlias.setValue2(35);final JSONObject jsonObject = JSONUtil.parseObj(beanWithAlias);Assert.asse...
2023-01-29
jackson序列化时区问题
念人之过必忘人之功——佚名 今天发现返回给前端的Date和数据库中查到的时间对不上 排查发现是Jackson指定时区问题,原先用的GMT+8,但数据库是Asia/Shanghai 123ObjectMapper shanghaiObjectMapper = new ObjectMapper() .setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")) .setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 引用:https://alphahinex.github.io/2021/10/31/difference-between-gmt-plus-8-and-asia-shanghai/ 里面提到的 GMT+8 和 Asia/Shanghai 的区别 GMT+8 因为没有位置信息,所以无法使用夏令时 Asia/Shanghai 使用夏令时 时间戳字符串中不包含时区...
2022-05-11
solon
人若是看透了自己,便不会再小看别人。——老舍《骆驼祥子》 分享一个很赞的web框架 Solon 是一个微型的 Java 开发框架。项目从 2018 年启动以来,参考过大量前人作品;历时两年,4000 多次的 commit;内核保持 0.1m 的身材,超高的跑分,良好的使用体验。支持:RPC、REST API、MVC、WebSocket、Socket 等多种开发模式。 Solon 强调:克制 + 简洁 + 开放的原则;力求:更小、更快、更自由的体验。 官网地址:https://solon.noear.org/ gitee:https://gitee.com/noear/solon Solon 家簇成员图谱 上代码感受一下: Hello World: 12345678910111213141516171819202122232425262728293031323334353637//Handler 模式:public class App{ public static void main(String[] args){ SolonA...

阿超
我的名字叫阿超 年龄25岁 家在北京市 职业是软件开发 每天最晚也会在八点前回家 不抽烟 酒浅尝辄止 晚上十二点上床 保证睡足八个小时 睡前写一篇博客 再做二十分钟俯卧撑暖身 然后再睡觉 基本能熟睡到天亮 像婴儿一样不留下任何疲劳和压力 就这样迎来第二天的早晨 健康检查结果也显示我很正常 我想说明我是一个不论何时都追求内心平稳的人 不拘泥于胜负 不纠结于烦恼 不树立使我夜不能寐的敌人 这就是我在这社会的生活态度
Follow Me公告
This is my Blog