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

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

问题描述

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



我正在使用Eclipse Helios和


$ b $
Java(TM)SE运行时环境(build 1.8.0_05-b13)
Java HotSpot(TM)服务器虚拟机(构建25.5-b02,混合模式)

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



编辑:
代码:

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问好();

}

B

  package com.jax; // **错误在这里** 

import javax.jws.WebService;

@WebService(endpointInterface =com.jax.WebServiceInter)
public class WebServiceImpl实现WebServiceInter {
@Override
public String sayHello(){
返回你好!;
}
}

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

解决方案

Java 8支持默认方法在接口。而在JDK 8中,很多旧接口现在都有新的默认方法。例如,现在在CharSequence中,我们有chars和codePoints方法

如果项目的源级别低于1.8,那么编译器不允许在接口中使用默认方法。所以它不能直接编译直接依赖于这个接口的类。

如果我得到你的问题,那么你有两个解决方案。第一个解决方案是回滚到JDK 7,那么你将使用旧的CharSequence接口,而不用默认方法。第二个解决方案是将项目的源级别设置为1.8,那么编译器就不会抱怨接口中的默认方法。


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.

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)

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

EDIT: Code:
Class 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:

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

解决方案

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天全站免登陆