I declare a method that gets a List
of type Object
. However, when I try to recognize it with instanceof
it gives error. I tried to do a casting but it still gave an error and I could not identify where the problem is in my code. Can anyone help?
public static void insertLog(List<Object> list) throws IOException{
if (list instanceof List<Transaction>){
for(Transaction transaction : list){
insertLog(transaction.toString());
}
}
else if (list instanceof List<Data>){
for(Data data : list){
insertLog(data.toString());
}
}
}
public static void insertLog(CashTransactionRequest request) throws IOException{
insertLog(request.getClient().getCustomer());
insertLog(request.getClient().getTeller());
insertLog(request.getClient().getTellerName());
insertLog(request.getDevice().getCountryId());
insertLog(request.getDevice().getDelegation());
insertLog(request.getDevice().getDeviceId());
insertLog(request.getDevice().getDeviceName());
insertLog(request.getDevice().getDeviceType());
insertLog(request.getDevice().getTimeZone());
insertLog(request.getAdditionalData().getData());
insertLog(request.getTransaction());
}