此时情绪此时天,无事小神仙
好好生活,平平淡淡每一天

编辑

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");
    }

image

posted @ 2021-10-26 11:44  踏步  阅读(67)  评论(2编辑  收藏  举报