找不到接口参数功能

时间:2012-10-29 02:27:57

标签: 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);
    }
}

这看起来很简单,但由于某种原因,我得到以下编译器错误:

error: cannot find symbol
closeQuietly(cl);
^
symbol:   method closeQuietly(Closeable)
location: class Utils

我不明白为什么。

1 个答案:

答案 0 :(得分:0)

我在ideone.com上尝试了你的代码并且编译得很好。

从编译错误消息中,显然找不到closeQuietly(Closeable),并且“箭头”指向方法名称,很可能没有这种名称的方法存在。如果您的实际代码中有任何拼写错误,请再次检查。