包声明中无法解析 java.lang.CharSequence 类型 [英] The type java.lang.CharSequence cannot be resolved in package declaration

查看:28
本文介绍了包声明中无法解析 java.lang.CharSequence 类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 P 包中得到 2 个类.接口类A及其实现类B.在具有 B 类的文件中,我收到以下错误:无法解析类型 java.lang.CharSequence.它是从所需的 .class 文件间接引用的.

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

我正在使用 Eclipse Helios 和

I'm using Eclipse Helios and

$ 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)

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

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

代码:
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();

}

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!";
    }
}

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

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

推荐答案

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

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.

这篇关于包声明中无法解析 java.lang.CharSequence 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆