So I'm trying to do a really simple interface and super class, and I'm getting an issue with my @Override
statements saying annotation type not applicable to this kind of declaration
. Now I saw this * questions that said it was a simple spelling error, but I checked my interface and my class and the function signatures are the same. Here is the interface:
所以我试图做一个非常简单的接口和超类,我的@Override语句问题是说注释类型不适用于这种声明。现在我看到这个*问题说这是一个简单的拼写错误,但我检查了我的界面和我的类和功能签名是相同的。这是界面:
package cit260.harrypotter.view;
public interface ViewInterface {
public void display();
public String[]getInputs();
public String getInput(String promptMessage);
public boolean doAction(String[] inputs);
}
and here is the super class:
这是超级课程:
package cit260.harrypotter.view;
import java.util.Scanner;
public abstract class View implements ViewInterface {
public View() {
@Override
public void display(){
boolean endView = false;
do {
String[] inputs = this.getInputs();
endView = doAction(inputs);
} while (!endView);
}
@Override
public String getInput(String promptMessage) {
String input;
boolean valid = false;
while(!valid) {
System.out.println(promptMessage);
Scanner keyboard = new Scanner(System.in);
input = keyboard.nextLine(); input.trim();
if (input.length != 0){
System.out.println("Please enter a valid input");
valid = true;
}
}
return input;
}
}
}
What am I doing wrong??
我究竟做错了什么??
2 个解决方案
#1
2
You have declared the methods inside the contructor. View() is a constructor which is used for initializing values for your class. You need to take your methods outside the constructor. Place them within the class alongside your constructor. Use an IDE to develop. Then these errors could be figured out while you are writing the code.
您已在构造函数内声明了方法。 View()是一个构造函数,用于初始化类的值。你需要在构造函数之外使用你的方法。将它们放在与构造函数一起的类中。使用IDE进行开发。然后在编写代码时可以找出这些错误。
#2
1
A constructor is used for initializing the value of the variable in your class. If you are implementing an interface then you have to override the method of the interface in your class.
构造函数用于初始化类中变量的值。如果要实现接口,则必须覆盖类中接口的方法。
#1
2
You have declared the methods inside the contructor. View() is a constructor which is used for initializing values for your class. You need to take your methods outside the constructor. Place them within the class alongside your constructor. Use an IDE to develop. Then these errors could be figured out while you are writing the code.
您已在构造函数内声明了方法。 View()是一个构造函数,用于初始化类的值。你需要在构造函数之外使用你的方法。将它们放在与构造函数一起的类中。使用IDE进行开发。然后在编写代码时可以找出这些错误。
#2
1
A constructor is used for initializing the value of the variable in your class. If you are implementing an interface then you have to override the method of the interface in your class.
构造函数用于初始化类中变量的值。如果要实现接口,则必须覆盖类中接口的方法。