java - What is the class of Map - Stack Overflow
parameterized - Java map, key = class, value = instance of that class - Stack Overflow
Policy-map and class-map
Python, is map a class or function - Stack Overflow
Videos
I think you mean something like this:
public class T {
public T(Class<Map<MyClassType1, Object>> cls) {
}
}
But you'll need this instead:
public class T {
public T(Class<? extends Map<MyClassType1, Object>> cls) {
}
public static void main(String[] args) {
Map<MyClassType1, Object> m = new HashMap<MyClassType1, Object>();
T t = new T(m.getClass());
}
}
Map is an interface. There are many implementations available for example HashMap.
Java's type system is simply not strong enough to enforce the type constraint you're describing directly, and you'll need to do some unsafe casts to make this work -- or wrap the Map in some other API that enforces the type safety. Guava's ClassToInstanceMap does just that for exactly this use case, providing an externally safe API that imposes additional restrictions on the Map interface to make it work. (Disclosure: I contribute to Guava.)
The only time this can cause a memory leak is if there's some classes you're using here that would not be retained for the life of the application. This isn't a concern for many users, especially if you're writing a "server side" application that isn't as concerned about unloading unused classes.
What you are using is a heterogeneous container. These can be made typesafe by using type tokens (as you already do) and Class.cast() with the correct application logic: So there is an unchecked suppressWarning within Class.cast(), but the application logic guarantees correctness.
I advise you read Josh Bloch's Effective Java Item 29: Consider typesafe heterogeneous containers. His example is:
// Typesafe heterogeneous container pattern - implementation
public class Favorites {
private Map<Class<?>, Object> favorites =
new HashMap<Class<?>, Object>();
public <T> void putFavorite(Class<T> type, T instance) {
if (type == null)
throw new NullPointerException("Type is null");
favorites.put(type, instance);
}
public <T> T getFavorite(Class<T> type) {
return type.cast(favorites.get(type));
}
}
I only see a possibility for memory leakage if you hold arbitrarily many different types you actually no longer need.
I'm trying to decipher a router config and I am trying to figure out how these 2 command work together. I've been reading about it but I need someone to explain it to me like I'm 5.
Also, how would I go about determining which of these VLANs is identified as a voice VLAN? There is no obvious voice configurations it looks like all the voice data is being handled by the SIP trunk but I can't figure out which IP is the SIP trunk...
anyway..