java - 更改 Eclipse 中的返回类型错误

标签 java eclipse return-type

我在 Eclipse 中不断收到以下错误:

"The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, String)"

这是代码:

public class names {

private String nameOne;
  public void setName(String name){
     nameOne=name;
  }
  public String getName(){
     return nameOne;
  }
  public void saying(){
     System.out.printf("Your name is %s", getName());
  }
}

请帮忙解释一下我应该做什么。我试图删除“String”,但那很愚蠢。我有点新,所以详细的解释不会太过分(尽管简短、简单、正确的回答总是最好的)。

最佳答案

The issue was due to the wrong Compiler compliance level

要解决这个问题,您必须通过执行此操作来更改 Eclipse 中的编译器合规级别

1) 右键单击​​您的项目

2) 单击“属性”

3)点击左侧菜单中的“Java编译器”选项

4) 在右侧的 JDK 合规性部分下,将其更改为“1.5”或更高版本

Java Compiler compliance level

The Compiler compliance level indicates that which JDK level of source must be used for compilation.

例如:

If you are using some components which is defined in earlier versions of Java JDK and was removed from the later versions. Then you must use the older version of JDK to compile your code. For this the eclipse provide the use of multiple compliance level, ie; even if you are using the latest version of JDK. You can tell the compiler to compile with an older version.

JDK 1.5 在 java.io.PrintStream 类中实现了 printf() 方法,该方法提供与 C 语言 stdio 库中 printf 函数相同的格式化功能。 关注Other Developer-Friendly Enhancements了解详情。

关于java - 更改 Eclipse 中的返回类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22776968/

相关文章:

java - "Best"具有 ODBC 和套接字的基于浏览器的应用程序的语言/架构? (主观)

java - 除了 SimpleDateFormat 之外,如何在时间设置上添加一个小时?

java - 错误 : 'void' type not allowed here

java - 为 Java 类创建 equal 方法来比较 double 或 int 值

javascript - 在Java中创建可读的Javascript以添加到html页面的最佳方法

java - 如何根据状态更新 GUI

eclipse - 有没有完整的 Eclipse 皮肤可用?

java - Eclipse 说堆已损坏

java - 如何从方法返回接口(interface)

c# - 如果返回类型是 char,如何返回 0