Salve a tutti. Come faccio in un metodo a ritornare due oggetti di tipo diverso? ad esempio nella signature dichiaro che il tipo di oggetto di ritorno è un int, ma dentro al metodo, in base a quello ke succede, alla fine può ritornare anke un tipo String...come faccio x fare in modo ke li possa ritornare tutti e 2? ecco il mio caso specifico:
codice:
public Scheda getScheda(int code) throws NotPresentException{
Iterator<Scheda> it = sch.iterator();
Iterator<SchedaDitta> it2 = schDit.iterator();
SchedaDitta di = null;
Scheda sc = null;
boolean presente=false;
boolean presente2=false;
while(it.hasNext()){
Scheda s = it.next();
if(s.getNum()==code){
sc=s;
presente=true;
}
}
while(it2.hasNext()){
SchedaDitta d = it2.next();
if(d.getNum()==code){
di=d;
presente2=true;
}
}
if(presente==false || presente2==false){
throw new NotPresentException();
}else {
if (presente==true){
return sc;
}else if (presente2==true){
return di;
}
}
}
Il tipo dikiarato di return è Scheda, ma può ritornare anke una SchedaDitte, ke è diversa...come posso fare? grazie.