Java - Converting from string to generic type -
in c# this
public static tconvertible changetype<tconvertible>(object value) tconvertible : iconvertible { try { if (value == null) return default(tconvertible); return (tconvertible)convert.changetype(value, typeof(tconvertible)); } catch (system.formatexception) { return default(tconvertible); } } is there way similar in java? using android sharedpreferences , trying wrap management class around it. rather using getstring, getint, getlong, etc, i'd pass in value, store string, , convert on it's way out.
i believe isn't possible due java's implementation of generics , whole type erasure issue wouldn't know tconvertible @ runtime.
Comments
Post a Comment