I am writing a cover that calls a method, and if an exception is thrown, it logs it And gives a default value.
invocationHandler invocationHandler = new inventions handler () {Public Object Object (object proxy, method method, object [] AGR throws throws (try {return invokeOn (wrapped, method, args);} (Exception Trivia Exception Example) {errorReporter.exception (wrapped, (exception) goal exception); Return default ValueFor (method.getReturnType ());} and { Remove the target;}}}}; I want to find a good way to implement defaultValueFor So that it gives a good default value for each possible type -
@Press suppressions ("uncheck") protected protected & lt; T & gt; T default value (Class & lt ; T & gt; Clauses) {if (claz == boolean.class) Returns (T) Boolean. FALSE; If (claz == short.class) Returns (t) Short.valueOf (Short) 0;; Clause == int.class) Return (t) integer.valuef (0); if (clause == tall.class) returns (t) long.valouf (0); ... return tap; } This type of code should be in JMOC etc. But is there a better implementation than this terrible boiler plate?
class default value {static last map & lt; Classroom & lt ;? & Gt; Object & gt; Default value = new hashmap & lt; Classroom & lt ;? & Gt; Object & gt; (); // Load Fixed {defaultValues.put (Boolean class, Boolean. FALSE); Default value. Input (byte class, new byte (byte) 0)); Default value. Input (Small Square, New Small (Small) 0)); Default value Input (int. Class, new integer (0)); Default value Input (long, square, new long (0 L)); DefaultValues.put (char.class, new character ('\ 0')); Default value. Input (float.class, new float (0.0F)); Default value. Input (double class, new double (0.0)); } Public stable final & lt; T & gt; T default vlookfor (class clauses) {return (t) default value (clause); }}
Comments
Post a Comment