为什么我应该创建一个以类型作为类名的方法,而不是像 void、int... 这样的原始类型?
BufferedImage imagetest(String file) throws IOException{
return null;
}
为什么 BufferedImage 类型不是 void 或类似的东西?我知道这是一个愚蠢的问题,但我希望有人能提供帮助。
最佳答案
这里,BufferedImage
是返回的数据类型。它可以是任何其他类类型,例如String
,或原始类型,例如int
。
// This method returns a String
String method() {
return "";
}
// This method returns an int
int method() {
return 0;
}
如果您不需要返回值,而只想做某事,则可以使用void
。
// This method doesn't return anything
void method() {
...
}
关于java - 以类名作为类型的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35260517/