我有一个转换器接口,它接受对象作为参数,对象是ClaimRecord和CustomerClaim:
List<ClaimsTOObject> convert(final Object claimObject);
如何检查哪个对象类作为输入参数传递来处理业务逻辑,因为我知道使用instanceof是一种反模式
您可以尝试像这样使用instanceOf(只需确保两个类相关):
if (object instanceof ClaimRecord) {
// code to execute if object is an instance of ClaimRecord
} else if (CustomerClaim) {
// code to execute if object is not an instance of CustomerClaim
}