Java 找不到接口参数函数
我有以下代码:Java 找不到接口参数函数,java,interface,parameters,Java,Interface,Parameters,我有以下代码: public class Utils{ public static void closeQuietly(Closeable c){ try{c.close();} catch(Exception e){} } public static void main(String [] args){ Closeable cl = new Socket(); closeQuietly(cl); } } 这
public class Utils{
public static void closeQuietly(Closeable c){
try{c.close();} catch(Exception e){}
}
public static void main(String [] args){
Closeable cl = new Socket();
closeQuietly(cl);
}
}
这似乎很简单,但出于某种原因,我得到了以下编译器错误:
error: cannot find symbol
closeQuietly(cl);
^
symbol: method closeQuietly(Closeable)
location: class Utils
我不明白为什么。我在ideone.com上试过你的代码,它编译得很好
从编译错误消息中,很明显它找不到
closequilly(Closeable)
,并且“箭头”指向方法名称,很可能不存在具有此名称的方法。请再次检查您的实际代码是否有任何输入错误。可能c.close代码>让人困惑。尝试c.close()
@John3136:您已更正了一个错误(1+),但这不会导致他显示的编译错误,我不认为。是的,它是c.close()。我只是在复印粘贴时错过了它。我会更新这个问题。我不知道你会遇到什么编译器错误,但要小心--Socket
只在Java 7+中实现了Closeable
。@BlueBullet:那不是运行时的CCE吗?