包声明中无法解析 java.lang.CharSequence 类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24301986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 11:22:33  来源:igfitidea点击:

The type java.lang.CharSequence cannot be resolved in package declaration

javaeclipse

提问by user3712116

I get 2 classes in package P. Interface class Aand its implementation class B. In the file with class BI get the following error: The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files.

我在 package 中有 2 个类P。接口类A及其实现类B。在带有类的文件中,B我收到以下错误:The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files.

I'm using Eclipse Helios and

我正在使用 Eclipse Helios 和

$ java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) Server VM (build 25.5-b02, mixed mode)

Standard solution of removing and adding JRE doesn't work. How can I fix it?

删除和添加 JRE 的标准解决方案不起作用。我该如何解决?

EDIT:Code:
Class A:

编辑:代码:
A

package com.jax;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;


@WebService
@SOAPBinding(style = Style.RPC)
public interface WebServiceInter {

@WebMethod
String sayHello();

}

Class B:

班级B

package com.jax; // **Error is here**

import javax.jws.WebService;

@WebService(endpointInterface = "com.jax.WebServiceInter")
public class WebServiceImpl implements WebServiceInter{
    @Override
    public String sayHello(){
        return "Hello!";
    }
}

Project structure: ProjectName -> Java Resources -> com.jax -> Class A, Class B

项目结构:ProjectName -> Java Resources -> com.jax -> Class A, ClassB

采纳答案by mkrakhin

Java 8 supports default methodsin 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.

Java 8 支持接口中的默认方法。在 JDK 8 中,许多旧接口现在都有新的默认方法。例如,现在在 CharSequence 我们有 chars 和 codePoints 方法
如果您的项目的源代码级别低于 1.8,那么编译器不允许您在接口中使用默认方法。所以它不能编译直接间接依赖这个接口的类。
如果我解决了您的问题,那么您有两种解决方案。第一个解决方案是回滚到 JDK 7,然后您将使用没有默认方法的旧 CharSequence 接口。第二种解决方案是将项目的源代码级别设置为 1.8,这样您的编译器就不会抱怨接口中的默认方法。

回答by akshay_rahar

"Java 8support for Eclipse Kepler SR2", and the new "JavaSE-1.8" execution environment showed up automatically.

Java 8支持Eclipse Kepler SR2”,新的“ JavaSE-1.8”执行环境自动出现。

Download this one:-Eclipse kepler SR2

下载这个:- Eclipse Kepler SR2

and then follow this link:- Eclipse_Java_8_Support_For_Kepler

然后点击此链接:- Eclipse_Java_8_Support_For_Kepler

回答by Arindam Sarkar

Make your Project and Workspace to point to JDK7 which will resolve the issue. https://developers.google.com/eclipse/docs/jdk_compliancehas given ways to modify Compliance and Facet level changes.

使您的项目和工作区指向 JDK7,这将解决该问题。 https://developers.google.com/eclipse/docs/jdk_compliance提供了修改合规性和方面级别更改的方法。

回答by Henry Li

Just trying to compile with ant, Have same error when using org.eclipse.jdt.core-3.5.2.v_981_R35x.jar, Everything is well after upgrade to org.eclipse.jdt.core_3.10.2.v20150120-1634.jar

只是尝试用ant编译,使用org.eclipse.jdt.core-3.5.2.v_981_R35x.jar时出现同样的错误,升级到org.eclipse.jdt.core_3.10.2.v20150120-1634.jar后一切正常

回答by Michael Fayad

Your Eclipse software suite doesn't support Java 1.8

您的 Eclipse 软件套件不支持 Java 1.8

Download a newer version of Eclipse.

下载较新版本的 Eclipse。