I'm trying to get the value of the following field via reflection:
Map<String,ClassLoader> loaders0 = new LinkedHashMap<String,ClassLoader>();
but when I try to get the value using field.get(new LinkedHashMap())
, I get the following:
java.lang.IllegalArgumentException: Can not set java.util.Map field loaders0 to java.util.LinkedHashMap
and seeing as Map is an interface I could not make a new Map interface to set it too. Does anybody know how to get around this?
Field loadersField = this.getPluginLoader().getClass().getDeclaredField("loaders0");
toggleFinal(loadersField);
Map<String, PluginClassLoader> loaders0 = (Map<String, PluginClassLoader>) loadersField.get(new LinkedHashMap<String, PluginClassLoader>());
loaders0.put(description.getName(), bcl);
loadersField.set(Map.class,loaders0);