项目实战—— 类型java.lang.charsequence不能解决(完美解决!)

在myEclipse中遇到错误'java.lang.CharSequence cannot be resolved'。问题源于IDE的编译器版本与JRE版本不匹配。解决方法包括降级JDK至1.6版本或升级IDE。理解问题本质是避免片面解决问题的关键。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:

   The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files

环境和配置

  我的myEclipse版本:

  Version: 10.7
  Build id: 10.7-20121026


编译器的版本:

   


问题的根源:


down vote accepted

Java 8 supports default methods in interfaces. And in JDK 8 a lot of old interfaces now have new default methods. For example, now in CharSequence we have chars and codePoints methods.
If source level of your project is lower than 1.8, then compiler doesn't allow you to use default methods in interfaces. So it cannot compile classes that directly on indirectly depend on this interfaces.
If I get your problem right, then you have two solutions. First solution is to rollback to JDK 7, then you will use old CharSequence interface without default methods. Second solution is to set source level of your project to 1.8, then your compiler will not complain about default methods in interfaces.

 

解决方案:

   1、对JDK进行降级。 

   2、对IDE进行升级(或者换一个高版本的Eclipse、idea)

我的处理方案:

   降级Jdk到已有的低版本1.6:效果图



问题最终完美解决。

小结:

   关于这个问题,网上有很多的解决方案,但是都没有将问题的根源找出来,不求甚解有时候是很可怕的一件事情,容易将问题片面化,长久就会造成在解决问题的时候我的思维会出现只见树木不见森林的问题。

   我们应该要在时间精力允许的情况下,尽可能从本质上根源上发现问题解决问题。本人也是在stackoverflow这个网站上发现了有个高手讲的东西。道出了问题的根源。其实是由于IDE本身支持的编译器版本和jre版本不匹配导致的。攻城狮,还是需要扎实的英语功底啊!

56 down vote accepted

Java 8 supports default methods in interfaces. And in JDK 8 a lot of old interfaces now have new default methods. For example, now in CharSequence we have chars and codePoints methods.
If source level of your project is lower than 1.8, then compiler doesn't allow you to use default methods in interfaces. So it cannot compile classes that directly on indirectly depend on this interfaces.
If I get your problem right, then you have two solutions. First solution is to rollback to JDK 7, then you will use old CharSequence interface without default methods. Second solution is to set source level of your project to 1.8, then your compiler will not complain about default methods in interfaces.

评论 33
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值