# 使用Class實例作為Map鍵是最佳實踐嗎？

Map classToInstance = new HashMap();

classToInstance.put(String.class,"Test obj");


## 最佳答案

This article explains the problem in detail. But in a nutshell, the problem is that each class contains a reference to its classloader, and each classloader contains references to every class that it has loaded. So if one class is reachable, all of them are.