Consider these 2 pieces of code (you can assume execeptionObj
is of type Object
, but we know it's an instance of Throwable
):
1)
logger.log(Level.ERROR, (Throwable) exceptionObj,
((Throwable) exceptionObj).getMessage());
2)
Throwable t = new Throwable((Throwable)exceptionObj);
logger.log(Level.ERROR, t, t.getMessage());
During a code review for a project I'm working on, one reviewer is saying that the first way is not as efficient as the second way because it involves 2 casts. I just wondered what you thought. It seems like creating a new instance would involve some overhead as well.