leetcode-helper
leetcode-helper copied to clipboard
编译时找不到符号
Buildfile: /leetcode-helper/build.xml
compile:
[echo] Compile source code for problem two_sum ...
[javac] Compiling 1 source file to /leetcode-helper/build
[javac] Compiling 1 source file to /leetcode-helper/build
[javac] /leetcode-helper/src/test/java/com/leetcode/two_sum/Tester.java:80: 错误: 找不到符号
[javac] int actual = solution.add(para1, para2);
[javac] ^
[javac] 符号: 方法 add(int,int)
[javac] 位置: 类型为Solution的变量 solution
[javac] 1 个错误
BUILD FAILED
/leetcode-helper/build.xml:108: Compile failed; see the compiler error output for details.
java version "1.8.0_101"
代码改成下面这样可以正常运行
Solution.java
interface Solution {
// use this Object to print the log (call from slf4j facade)
static Logger log = LoggerFactory.getLogger(Solution.class);
public int add(int a, int b);
}
Solution1.java
class Solution1 implements Solution {
@Override
public int add(int a, int b) {
return a + b;
}
}
也就是说生成代码的时候,少了
public int add(int a, int b);
和
@Override
666,是这个问题
接口的函数签名确实是要自己加的。考虑到每个人的习惯都不一样,我解析的话反而容易出错。