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

问题:

   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

项目实战—— 类型java.lang.charsequence不能解决(完美解决!)_第1张图片

编译器的版本:

   项目实战—— 类型java.lang.charsequence不能解决(完美解决!)_第2张图片

项目实战—— 类型java.lang.charsequence不能解决(完美解决!)_第3张图片

问题的根源:


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:效果图

项目实战—— 类型java.lang.charsequence不能解决(完美解决!)_第4张图片

项目实战—— 类型java.lang.charsequence不能解决(完美解决!)_第5张图片

问题最终完美解决。

小结:

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

   我们应该要在时间精力允许的情况下,尽可能从本质上根源上发现问题解决问题。本人也是在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.

你可能感兴趣的:(●项目,------【问题和一些想法】)