[英]Java return Object [on hold]
I don't know how to return the value of the string here, in short, I need the output of this string that is stored in the function:我这里不知道怎么返回字符串的值,总之我需要这个字符串的output存储在function中:
public Object Directory(String directory) {
String directory1 = "directory";
return directory1;
}
public static void main(String... args) throws Exception {
System.out.println(directory1);
}
This is my interface in another file:这是我在另一个文件中的界面:
public interface Interface extends Remote {
Object FileName(String filename) throws RemoteException;
Object Directory(String directory) throws RemoteException;
}
If I understand you.如果我理解你。 You can try so.你可以这样试试。
public static String Directory(String directory) {
String directory1 = "directory";
return directory1;
}
public static void main(String... args) throws Exception {
System.out.println(Directory("directory1"));
}
In Java you must declare the return type of a function.在 Java 中,您必须声明 function 的返回类型。 In your case you have defined the return type of Object
when you really want a return type of String
在您的情况下,当您真的想要返回类型为String
时,您已经定义了返回类型Object
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.