java常踩的坑
销毁字符串
/** * 销毁字符串 * @param destroyString */ public static void destroyString(String destroyString) { try { System.out.println("销毁前destroyString:"+destroyString); // 声明字段 Field field =String.class.getDeclaredField("value"); // set可访问 field.setAccessible(true); // convert to char[] char[] chars = (char[]) field.get(destroyString); // 替换为(char) 0x00 Arrays.fill(chars,(char) 0x00); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } finally { System.out.println("销毁后destroyString:"+destroyString); } } public static void main(String[] args) { /** * 销毁字符串 */ destroyString("abc"); }