/** * Reflectively run the <tt>String title()</tt> method if it exists, else * fall back to the <tt>toString()</tt> method. */ private static String titleFor(final Object object) { if (object == null) { return null; } else { Method method; try { method = object.getClass().getMethod("title", new Class[0]); return (String) method.invoke(object, new Object[0]); } catch (final SecurityException e) { throw new TitleBufferException(e); } catch (final NoSuchMethodException e) { return object.toString(); } catch (final IllegalArgumentException e) { throw new TitleBufferException(e); } catch (final IllegalAccessException e) { throw new TitleBufferException(e); } catch (final InvocationTargetException e) { throw new TitleBufferException(e); } } }
private static String titleFor(Object object) { if (object == null) { return null; } else if (object instanceof String) { return object.toString(); } else { try { Method e = object.getClass().getMethod("title", NO_PARAMETER_TYPES); return (String) e.invoke(object, NO_ARGUMENTS); } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | SecurityException var2) { throw new TitleBufferException(var2); } catch (NoSuchMethodException var3) { return object.toString(); } } }
/** * Reflectively run the <tt>String title()</tt> method if it exists, else * fall back to the <tt>toString()</tt> method. */ private static String titleFor(final Object object) { if (object == null) { return null; } if(object instanceof String) { return object.toString(); } try { Method method = object.getClass().getMethod("title", NO_PARAMETER_TYPES); return (String) method.invoke(object, NO_ARGUMENTS); } catch (final SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { throw new TitleBufferException(e); } catch (final NoSuchMethodException e) { return object.toString(); } }