Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Andreas Leitgeb Newsgroups: comp.lang.java.programmer Subject: Re: it's Closeable, but I don't want to close() it yet. Date: Wed, 27 Feb 2019 19:03:26 -0000 (UTC) Organization: A noiseless patient Spider Lines: 34 Message-ID: References: <709a1f3b-fc99-4bd0-a8b8-866092bb7ae9@googlegroups.com> Reply-To: avl@logic.at Injection-Date: Wed, 27 Feb 2019 19:03:26 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="bb077191349627e6d7efbb06e52b68a2"; logging-data="5316"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/idoWQdflfKBxjF1uBkIMr" User-Agent: slrn/1.0.3 (Linux) Cancel-Lock: sha1:qLOR2w7CgQTHDPPZRa572c6UNGU= Xref: csiph.com comp.lang.java.programmer:38741 Eric Douglas wrote: > On Wednesday, February 27, 2019 at 10:52:01 AM UTC-5, Andreas Leitgeb wrote: >> In my application there exists an entity that is Closeable. >> It is kept in some class, and other parts of my application >> request a ref to the entity and do actions on it, then drop >> their ref, leaving the entity intact. >> >> Everything runs fine, except eclipse warns me about spots >> where the entity is requested, used, and then dropped. >> Eclipse thinks it might need to be close()d. >> >> Apart from ignoring the warning per eclipse settings or >> adding @SuppressWarnings, is there maybe a way to tell >> the compiler that a certain ref is not meant to be close()d? >> Letting it know that - despite the entity's ultimate fate of >> being eventually closed - this is not yet the time&place for it? > > You probably don't want to ignore the warning type entirely. It sounds > like if it's getting used in one method and you'll guarantee it gets > closed elsewhere, you'll just want to add a SuppressWarnings to that > method. In the meantime, I could think of another solution: - create an interface that only offers those methods of the entity that are really needed for its "use", e.g. EntityUse - let the entity retriever method return the entity with a static type EntityUse - Then the "use"-part isn't aware of the entity's Closeability, and as an extra bonus, calling other methods is at least hidden behind the threshold of an explicit cast.. PS: I just added the @SuppressWarnings, but I feel better now knowing there would be also a clean "OO"-solution.