다른 유형의 값을 저장하고 반환 할 수있는 클래스가 필요합니다. 나는 내 수업을 정의 할 수 없었다. 내가 필요로하는 유일한 클래스는 List 클래스입니다. 데이터베이스 테이블에서 값을 검색합니다. 이 내 접근 방식 :가변 개수의 변수가있는 클래스
//the total number of these variables can vary. The same is true for their types;
int intValue = 1;
String stringValue = "text 1";
byte[] dataValue = new byte[4];
List row = new ArrayList();
row.add(intValue);
row.add(stringValue);
row.add(dataValue);
List rows = new ArrayList();
rows.add(row);
intValue = 6;
stringValue = "text 2";
dataValue = new byte[8];
row = new ArrayList();
row.add(intValue);
row.add(stringValue);
row.add(dataValue);
rows.add(row);
String text1 = (String) ((List)rows.get(0)).get(1);
String text2 = (String) ((List)rows.get(1)).get(1);
당신이 내 구현이 잘못 생각하기 때문에 제네릭 형식의 데이터를 저장할 수있는 더 좋은 방법을 제안 할 수 있습니다.
"제네릭 유형을 저장하는 더 좋은 방법을 제안 할 수 있습니까?"- 대답은 귀하의 질문입니다. – Maroun
동일한 데이터 구조에서'Object' 유형의 변수를 저장하는 것은 일반이 아니며 대부분의 경우 나쁜 설계입니다. – Dici
하지만 캐스팅은 어떨까요? 리소스를 많이 차지합니까? – vovahost