Real Life, Practical Example of Using String.intern() in Java?

后端 未结 5 1124
挽巷
挽巷 2021-01-01 11:47

I\'ve seen many primitive examples describing how String intern()\'ing works, but I have yet to see a real-life use-case that would benefit from it.

The only situati

5条回答
  •  一向
    一向 (楼主)
    2021-01-01 12:11

    Never, ever, use intern on user-supplied data, as that can cause denial of service attacks (as intern()ed strings are never freed). You can do validation on the user-supplied strings, but then again you've done most of the work needed for intern().

提交回复
热议问题