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: Thu, 28 Feb 2019 12:20:24 -0000 (UTC) Organization: A noiseless patient Spider Lines: 26 Message-ID: References: <709a1f3b-fc99-4bd0-a8b8-866092bb7ae9@googlegroups.com> <8e1597a2-5c18-4fd1-83a4-7667e4d11e77@googlegroups.com> Reply-To: avl@logic.at Injection-Date: Thu, 28 Feb 2019 12:20:24 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="736217a967b4422be6275df234d15eb4"; logging-data="17784"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19c8eLSQonweXhlUv1FpX+h" User-Agent: slrn/1.0.3 (Linux) Cancel-Lock: sha1:P2bixIgYhW+fFRwq+Kjisfnu5e4= Xref: csiph.com comp.lang.java.programmer:38746 Eric Douglas wrote: > On Wednesday, February 27, 2019 at 2:03:35 PM UTC-5, Andreas Leitgeb wrote: >> 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. > I haven't seen that warning lately. I only started to notice it after an upgrade from a rather old eclipse to a more current one. (That doesn't mean that it wasn't there before. Maybe it wasn't, maybe I just didn't notice it.) > Does it only warn you to close it if you explicitly call an > open method? You could just use a custom method/class to open > and close so it doesn't see that. The Closeable interface does not provide any concept of opening. Eclipse just sees a local variable of a Closeable type that goes out of scope without .close() being called on it.