Does Java support RAII/deterministic destruction?

前端 未结 4 1869
轻奢々
轻奢々 2020-12-08 00:37

It\'s been at least 5 years since I worked with Java, and back then, any time you wanted to allocate an object that needed cleaning up (e.g. sockets, DB handles), you had to

4条回答
  •  我在风中等你
    2020-12-08 01:15

    The approach I take is to use a layered product (sometime a simple static method) which takes care of the resource allocation. You don't want this sort of resource allocation littering your program.

    There are plenty of libraries which do this. It not something you should have to worry about in most cases.

提交回复
热议问题