callingmethod(){
File f=new File();
//...
String s= new String();
//...
method(f + s); // here is problem (most put f+s in object to send it to method)
}
캔트 변경 방법은 인수하지 분명 어떤 일이하나의 오브젝트에서 두 개의 다른 오브젝트 유형을 병합하는 방법은 무엇입니까?
callingmethod(){
File f=new File();
//...
String s= new String();
//...
method(f + s); // here is problem (most put f+s in object to send it to method)
}
캔트 변경 방법은 인수하지 분명 어떤 일이하나의 오브젝트에서 두 개의 다른 오브젝트 유형을 병합하는 방법은 무엇입니까?
PLZ 물어 당신은 예를 들어, 수에 대한
method(Object o){
//...
//how to split it to file and String here
}
배열에 넣어 :
method (new Object[] {f, s});
void method (Object o) {
final Object[] arr = (Object[]) o;
File f = (File) arr[0];
String s = (String) arr[1];
}
가장 깨끗하고 가장 관용적 인 방법은 당신의 쌍을 나타내는 간단한 클래스를 만드는 것입니다 :
static class FileString {
public final File f;
public final String s;
FileString(File f, String s) {
this.f = f; this.s = s;
}
}
다음 방법 내부
method(new FileString(file, string));
쓰기 :
를FileString fs = (FileString)o;
// use fs.f and fs.s
종속 자세한 내용은 예제에서와 같이 중첩 된 클래스를 사용하거나 자체 파일에 넣으십시오. 인스턴스화하는 곳과 가까운 곳에두면 생성자를 private 또는 package-private로 만들 수 있습니다. 그러나 이것들은 더 정밀한 세부 사항 일뿐입니다.
답변 해 주셔서 감사합니다. –